This is my first time using WPF, I have a usercontrol with a ToolBar, and ToolBarPanels on that ToolBar. My problem is trying to right align the very last ToolBarPanel which contains some buttons.
http://imgur.com/n5v4YCw
I have scoured the interwebs and tried solutions (wrap it in a grid, dockpanel, stackpanel) but none have worked.
My XAML is:
<ToolBar
HorizontalAlignment="Left" Width="{Binding ActualWidth, ElementName=userControl}"
VerticalAlignment="Top"
Name="ToolBarPanel1"
UseLayoutRounding="False"
ToolBarTray.IsLocked="True">
<ToolBar.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF475B7E" Offset="1"/>
<GradientStop Color="#FFB9C3D5" Offset="0.427"/>
</LinearGradientBrush>
</ToolBar.Background>
.........
<ToolBarPanel ToolBar.OverflowMode="AsNeeded" Orientation="Horizontal" HorizontalAlignment="Right" >
<Button
Name="btnPrint"
Margin="5"
HorizontalAlignment="Right"
VerticalAlignment="Center"
BorderThickness="1"
IsEnabled="{Binding Path=AllowEdit}"
BorderBrush="#FF586A8B"
DockPanel.Dock="Right"
Visibility="{Binding Path=ControlVisibility.Print,
Converter={StaticResource BooleanToVisibilityConverter}}">
<Image Source="/component/Images/print-image.png"></Image>
<Button.ToolTip>
<ToolTip>
<TextBlock>Print Chart</TextBlock>
</ToolTip>
</Button.ToolTip>
</Button>
<Button
Name="btnCopy"
Margin="5"
HorizontalAlignment="Right"
VerticalAlignment="Center"
BorderThickness="1"
IsEnabled="{Binding Path=AllowEdit}"
BorderBrush="#FF586A8B"
Visibility="{Binding Path=ControlVisibility.Copy,
Converter={StaticResource BooleanToVisibilityConverter}}">
<Image Source="/component/Images/copy-image.png"></Image>
<Button.ToolTip>
<ToolTip>
<TextBlock>Copy Chart to Clipboard</TextBlock>
</ToolTip>
</Button.ToolTip>
</Button>
<Button
Name="btnInfo"
Margin="5"
HorizontalAlignment="Right"
VerticalAlignment="Center"
BorderThickness="1"
IsEnabled="{Binding Path=AllowEdit}"
BorderBrush="#FF586A8B"
Visibility="{Binding Path=ControlVisibility.Info,
Converter={StaticResource BooleanToVisibilityConverter}}">
<Image Source="/component/Images/help-image.png"></Image>
<Button.ToolTip>
<ToolTip>
<TextBlock>Chart Help</TextBlock>
</ToolTip>
</Button.ToolTip>
</Button>
</ToolBarPanel>
</ToolBar>
Well stretched grid with last columndefinition set to "*" should fulfill your goal. Also you can try using DockPanel and aligning like this:
<DockPanel>
<ToolBarPanel DockPanel.Dock="Left"/>
<ToolBarPanel DockPanel.Dock="Left"/>
<ToolBarPanel DockPanel.Dock="Left"/>
<!-- Last One -->
<ToolBarPanel DockPanel.Dock="Right"/>
</DockPanel>
Related
I have a listbox in WPF which consists of few labels and a rectangle.
I am trying to get all the label values of items in a ListBox.
My WPF markup for ListBox is:
<ListBox x:Name="izabraniList" ItemTemplate="{DynamicResource izabraniIzbornik}" Margin="0,80,10,108" HorizontalAlignment="Right" Width="289" Background="{x:Null}" ScrollViewer.HorizontalScrollBarVisibility="Hidden">
<ListBox.Resources>
<DataTemplate x:Key="izabraniIzbornik">
<Border BorderBrush="white" CornerRadius="2,2,2,2" BorderThickness="1,1,1,1">
<StackPanel Orientation="Horizontal" Width="254" Height="64" UseLayoutRounding="False" Opacity="100">
<DockPanel>
<Rectangle Height="62" Width="62"
Margin="2,0" RadiusX="5" RadiusY="5" >
<Rectangle.Fill>
<ImageBrush ImageSource="{Binding Path=ART_SIFRA, Converter={StaticResource ImageSourceConverter}}"/>
</Rectangle.Fill>
</Rectangle>
</DockPanel>
<DockPanel Width="133" >
<Label Content="{Binding ART_NAZIV}"
VerticalAlignment="Center"
HorizontalAlignment="left"
FontSize="12" Width="auto" Foreground="#FF303030" FontWeight="Bold" />
</DockPanel>
<DockPanel HorizontalAlignment="right" Width="55" Height="64">
<DockPanel HorizontalAlignment="Right" VerticalAlignment="top" Height="20" FlowDirection="RightToLeft"/>
<DockPanel HorizontalAlignment="Right" VerticalAlignment="bottom" Height="64" FlowDirection="RightToLeft" Width="55">
<Label x:Name="cijena" Content="{Binding SKC_PRICE}" FontSize="11" DockPanel.Dock="Right" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" Width="55" />
<Label Content="{Binding kolicina}" FontSize="11" DockPanel.Dock="Right" HorizontalAlignment="left" VerticalAlignment="top" FontWeight="Bold" Width="55" />
</DockPanel>
</DockPanel>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.Resources>
</ListBox>
And I would like to do something like this:
For Each i As String In izabraniList.Items("SKC_PRICE")
Console.WriteLine(i)
Next
make a separate property in your class that flattens the list (i.e.
public string property { get { return String.Join(", ", izabranilist.Select(x => x.Skc_Price).toarray()); } }
and then bind that to the label.
I have 3 regions namely Menu,Toolbar and Content. When a module(ie customer) is clicked in Menu view it will navigate to the respective view in content region, after editing the values in the textboxes I need to save that to DB. How to get the underlaying view model of the active view and send to DAL when save button is clicked in Toolbar view?.
Shell.xaml:
<Grid DockPanel.Dock="Left" Width="65" Margin="1">
<Border CornerRadius="1" BorderBrush="Black" BorderThickness="1">
<StackPanel Orientation="Vertical" Margin="1" >
<ContentControl Name="menuControl" PrismRegions:RegionManager.RegionName="{x:Static infra:RegionNames.MenuRegion}"/>
</StackPanel>
</Border>
</Grid>
<Grid DockPanel.Dock="Top" Margin="1">
<Border CornerRadius="1" BorderBrush="Black" BorderThickness="1" >
<StackPanel Orientation="Vertical" Margin="2">
<ContentControl Name="toolbarControl" PrismRegions:RegionManager.RegionName="{x:Static infra:RegionNames.ToolbarRegion}"/>
</StackPanel>
</Border>
</Grid>
<Grid DockPanel.Dock="Right" Margin="2">
<Border CornerRadius="1" BorderBrush="Black" BorderThickness="1">
<StackPanel Margin="5" >
<ContentControl Name="contentControl" DockPanel.Dock="Top" PrismRegions:RegionManager.RegionName="{x:Static infra:RegionNames.ContentRegion}"/>
</StackPanel>
</Border>
</Grid>
Menu.xaml:
<Button Grid.Row="0" Name="btnHome" Background="Transparent" Margin="1" ToolTip="Home" Command="{x:Static inf:ApplicationCommands.NavigationCommand}" CommandParameter="{x:Type mod:HomeView}">
<TextBlock Height="32" Width="32" Text ="">
<TextBlock.Background>
<ImageBrush Stretch="Fill" ImageSource="/Modules;component/Icons/home_32.png"/>
</TextBlock.Background>
</TextBlock>
</Button>
<Button Grid.Row="1" Name="btnBank" Background="Transparent" Margin="1" ToolTip="Bank" Command="{x:Static inf:ApplicationCommands.NavigationCommand}" CommandParameter="{x:Type mod:BankView}">
<TextBlock Height="32" Width="32" Text ="">
<TextBlock.Background>
<ImageBrush Stretch="Fill" ImageSource="/Modules;component/Icons/bank_64.png"/>
</TextBlock.Background>
</TextBlock>
</Button>
<Button Grid.Row="2" Name="btnCustomer" Background="Transparent" Margin="1" ToolTip="Customer" Command="{x:Static inf:ApplicationCommands.NavigationCommand}" CommandParameter="{x:Type mod:CustomerView}">
<TextBlock Height="32" Width="32" Text ="">
<TextBlock.Background>
<ImageBrush Stretch="Fill" ImageSource="/Modules;component/Icons/customer_128.ico"/>
</TextBlock.Background>
</TextBlock>
</Button>
<Button Grid.Row="3" Name="btnEmployee" Background="Transparent" Margin="1" ToolTip="Employee" Command="{x:Static inf:ApplicationCommands.NavigationCommand}" CommandParameter="{x:Type mod:EmployeeView}">
<TextBlock Height="32" Width="32" Text ="">
<TextBlock.Background>
<ImageBrush Stretch="Fill" ImageSource="/Modules;component/Icons/employee_128.png"/>
</TextBlock.Background>
</TextBlock>
</Button>
Toolbar.xaml:
<Button Grid.Column="0" Margin="1" Name="btnAdd" Height="35" Width="35" ToolTip="Add" Background="Transparent" Command="{Binding AddCommand}" CommandParameter="Add" >
<TextBlock Height="30" Width="30" Text ="">
<TextBlock.Background>
<ImageBrush Stretch="Fill" ImageSource="/Modules;component/Icons/plus_32.png"/>
</TextBlock.Background>
</TextBlock>
</Button>
<Button Grid.Column="1" Margin="1" Name="btnEdit" Height="35" Width="35" ToolTip="Edit" Background="Transparent" Command="{Binding EditCommand}" CommandParameter="Edit" >
<TextBlock Height="30" Width="30" Text ="">
<TextBlock.Background>
<ImageBrush Stretch="Fill" ImageSource="/Modules;component/Icons/pencil_32.png"/>
</TextBlock.Background>
</TextBlock>
</Button>
<Button Grid.Column="2" Margin="1" Name="btnSave" Height="35" Width="35" ToolTip="Save" Background="Transparent" Command="{Binding SaveCommand}" CommandParameter="Save" >
<TextBlock Height="30" Width="30" Text ="">
<TextBlock.Background>
<ImageBrush Stretch="Fill" ImageSource="/Modules;component/Icons/save_32.png"/>
</TextBlock.Background>
</TextBlock>
</Button>
<Button Grid.Column="3" Margin="1" Name="btnPrint" Height="35" Width="35" ToolTip="Print" Background="Transparent" Command="{Binding PrintCommand}" CommandParameter="Print" >
<TextBlock Height="30" Width="30" Text ="">
<TextBlock.Background>
<ImageBrush Stretch="Fill" ImageSource="/Modules;component/Icons/print_32.png"/>
</TextBlock.Background>
</TextBlock>
</Button>
UI Design:
Basically your view's state is entirely present in the viewmodel. In your scenario of Button being out side the viewmodel of the form to save what you can do is:
In tool bar viewmodel:
Raise an event that Save button is clicked
myEventAggregator.RaiseEvent<SaveButtonClicked>().Publish(args);
On viewmodel constructor:
subscribe for the event that you raise when you click on save button in toolbar region
myEventAggregator.GetEvent<SaveButtonClicked>().Subscribe(yourSubscriberDelegate);
On Exit of the form or cancel of form:
Unsubscribe for the event. (this makes sure you don't have multiple active forms saving the data at the same time)
myEventAggregator.GetEvent<SaveButtonClicked>().UnSubscribe(yourSubscriberDelegate);
For this you need Event aggregator knowledge of publish and subscribe. Find more details here
Can we able to create a MahApps Metro Master Animated Tab Control on to Metro Window title bar ?
I wrote a code like,
<Controls:MetroWindow.WindowCommands>
<Controls:WindowCommands HorizontalAlignment="Left">
<Grid HorizontalAlignment="Left">
<TabControl ItemsSource="{Binding Items1}" FontWeight="Thin" HorizontalAlignment="Left" HorizontalContentAlignment="Left">
<TabControl.ItemTemplate>
<DataTemplate>
<Grid>
<StackPanel Orientation="Horizontal">
<Rectangle Width="20" Height="10">
<Rectangle.Resources>
<SolidColorBrush x:Key="BlackBrush" Color="White"/>
</Rectangle.Resources>
<Rectangle.Fill>
<!--<VisualBrush Stretch="Fill" Visual="{StaticResource appbar_cupcake}" />-->
<ImageBrush Stretch="Fill" ImageSource="/Resources/Images/menu-home-off.png"></ImageBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock FontSize="14" FontWeight="Bold" Text="{Binding Name}"/>
</StackPanel>
</Grid>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<Label Margin="100 100 100 100" Content="{Binding Content}" Foreground="White" />
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
</Grid>
</Controls:WindowCommands>
</Controls:MetroWindow.WindowCommands>
The Tab ItemTemplate is displaying in Title Window, The ContentTemplate is not displaying....
Is it possible?
If yes, How can i achieve this ?
Thanks in advance !!
I am trying to create a ListViewItem template which looks like this, but i'm not making much headway.
Here is the style I have created so far:
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Border HorizontalAlignment="Stretch" Margin="1.5" CornerRadius="5" BorderThickness="1,1,1,1" BorderBrush="#FF997137">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF4B4B4B" Offset="0" />
<GradientStop Color="#FF8F8F8F" Offset="1" />
</LinearGradientBrush>
</Border.Background>
</Border>
<StackPanel Orientation="Horizontal" >
<Image HorizontalAlignment="Left" Width="32" Source="/Images/stop.png" Stretch="Fill" Height="32" />
<TextBlock Foreground="#FFECAD25" TextWrapping="Wrap" Width="150" >
This is a user control. The animation uses the attached BalloonShowing event.
</TextBlock>
<StackPanel Orientation="Vertical" >
<Image HorizontalAlignment="Right" Margin="0,10,5,0" VerticalAlignment="Top" Width="16" Height="16" Source="/Images/Close.png" Stretch="Fill"
Opacity="0.4" ToolTip="Delete" x:Name="Delete" />
<Image HorizontalAlignment="Right" Margin="0,5,5,0" VerticalAlignment="Top" Width="16" Height="16" Source="/Images/Close.png" Stretch="Fill"
Opacity="0.4" ToolTip="Edit" x:Name="Edit" />
</StackPanel>
</StackPanel>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
Is it possible to extend the text below the image/icon?
I don't believe there is any out-of-the box way to do this with a `TextBlock'.
However, if you are able to use the FlowDocument control, here are some options: answer 1, answer 2.
As far I know, no. Not atleast with simple Image and TextBlock.
FlowDocument seems to be good solution though,
check out this link for further information:
http://dotnetslackers.com/articles/wpf/WPFFlowDocumentsAndImages.aspx
I am creating dynamically ScatterView items using a template:
<s:ScatterView.ItemTemplate >
<DataTemplate>
<DockPanel LastChildFill="True" >
<DockPanel.Background>
<ImageBrush ImageSource="{Binding Type, Converter={StaticResource imgSelector}}"
Stretch="Fill" />
</DockPanel.Background>
<TextBox Background="Transparent" DockPanel.Dock="Top" Text="{Binding Path=Message}"
IsReadOnly="True" TextWrapping="Wrap" />
<s:ElementMenu Name="emBallMenu" VerticalAlignment="Top"
ActivationMode="HostInteraction" ActivationHost="?????">
<s:ElementMenuItem Header="Send back" x:Name="emiSendBack"
Command="local:MainSurfaceWindow.MenuItemCommand"
CommandParameter="{Binding Path=BallId}"/>
</s:ElementMenu>
</DockPanel>
</DataTemplate>
</s:ScatterView.ItemTemplate>
What should I set in the ActivationHost of the emBallMenu so that menu gets activated on a finger tap on the parent ScatterView.ItemTemplate?
The correct response is :
<s:ElementMenu Name="emBallMenu"
VerticalAlignment="Top"
ActivationMode="HostInteraction"
ActivationHost="{Binding RelativeSource=RelativeSource FindAncestor,
AncestorType={x:Type s:ScatterViewItem}}}"
/>
I found this in here