In WPF,
how do I spread/stretch content over an area (a wide horizontal area)?
Like this:
Here's my current code (from the upper part of the picture):
<Grid Width="900">
<ScrollViewer x:Name="sclScroller" HorizontalScrollBarVisibility="Hidden">
<Viewbox HorizontalAlignment="Stretch">
<DockPanel>
<TextBlock Name="txtContent1" Text="1" />
<TextBlock Name="txtContent2" Text="2" />
<TextBlock Name="txtContent3" Text="3" />
<TextBlock Name="txtContent4" Text="4" />
<TextBlock Name="txtContent5" Text="5" />
<TextBlock Name="txtContent6" Text="6" />
<TextBlock Name="txtContent7" Text="7" />
<TextBlock Name="txtContent8" Text="8" />
</DockPanel>
</Viewbox>
</ScrollViewer>
</Grid>
Using a uniform grid you can do something like that.
<UniformGrid Rows="1" Columns="8">
<UniformGrid.Resources>
<Style TargetType="TextBlock">
<Setter Property="HorizontalAlignment" Value="Center"></Setter>
</Style>
</UniformGrid.Resources>
<TextBlock Name="txtContent1" Text="1" />
<TextBlock Name="txtContent2" Text="2" />
<TextBlock Name="txtContent3" Text="3" />
<TextBlock Name="txtContent4" Text="4" />
<TextBlock Name="txtContent5" Text="5" />
<TextBlock Name="txtContent6" Text="6" />
<TextBlock Name="txtContent7" Text="7" />
<TextBlock Name="txtContent8" Text="8" />
</UniformGrid>
Related
I seem to be unable to auto-resize an AvalonDock control when its host window is resized. (In addition, the control should dock to the full window at startup, which is also eluding me.)
I've tried the HorizontalAlignment and VerticalAlignment properties, as advised here and several other places here on SO, but they're not working for this control. No control resizing takes place when the window is resized.
From the sound of it, the properties govern resizing a control for its child controls. However, I need to resize the control with its parent (the window).
Here's my XAML, copied from the Xceed sample and modified slightly to run in my environment:
<Window
x:Class="Docker"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock"
xmlns:s="clr-namespace:System;assembly=mscorlib"
Title="AvalonDock">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
Text="Usage:"
Style="{StaticResource Header}" />
<StackPanel Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<xcad:DockingManager x:Name="_dockingManager"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
AllowMixedOrientation="True"
BorderBrush="Gray"
BorderThickness="1">
<xcad:DockingManager.DocumentHeaderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding IconSource}"
Margin="0,0,4,0" />
<TextBlock Text="{Binding Title}" />
</StackPanel>
</DataTemplate>
</xcad:DockingManager.DocumentHeaderTemplate>
<xcad:LayoutRoot x:Name="_layoutRoot">
<xcad:LayoutPanel Orientation="Horizontal">
<xcad:LayoutAnchorablePane DockWidth="200">
<xcad:LayoutAnchorable ContentId="properties"
Title="Properties"
CanHide="False"
CanClose="False"
AutoHideWidth="240"
IconSource="..\Images\table-gear.png">
<xctk:PropertyGrid NameColumnWidth="110"
SelectedObject="{Binding ElementName=_layoutRoot, Path=LastFocusedDocument.Content}"
AutoGenerateProperties="False">
<xctk:PropertyGrid.PropertyDefinitions>
<xctk:PropertyDefinition TargetProperties="Background" />
<xctk:PropertyDefinition TargetProperties="BorderBrush" />
<xctk:PropertyDefinition TargetProperties="BorderThickness" />
<xctk:PropertyDefinition TargetProperties="FontSize" />
<xctk:PropertyDefinition TargetProperties="FontStyle" />
<xctk:PropertyDefinition TargetProperties="Width" />
<xctk:PropertyDefinition TargetProperties="Height" />
</xctk:PropertyGrid.PropertyDefinitions>
</xctk:PropertyGrid>
</xcad:LayoutAnchorable>
</xcad:LayoutAnchorablePane>
<xcad:LayoutDocumentPaneGroup>
<xcad:LayoutDocumentPane>
<xcad:LayoutDocument ContentId="document1"
Title="Document 1"
IconSource="..\Images\document.png">
<Button Content="Document 1 Content"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</xcad:LayoutDocument>
<xcad:LayoutDocument ContentId="document2"
Title="Document 2"
IconSource="..\Images\document.png">
<TextBox Text="Document 2 Content"
AcceptsReturn="True" />
</xcad:LayoutDocument>
</xcad:LayoutDocumentPane>
</xcad:LayoutDocumentPaneGroup >
<xcad:LayoutAnchorablePaneGroup DockWidth="125">
<xcad:LayoutAnchorablePane>
<xcad:LayoutAnchorable ContentId="alarms"
Title="Alarms"
IconSource="..\Images\alarm.png"
CanClose="True">
<ListBox>
<s:String>Alarm 1</s:String>
<s:String>Alarm 2</s:String>
<s:String>Alarm 3</s:String>
</ListBox>
</xcad:LayoutAnchorable>
<xcad:LayoutAnchorable ContentId="journal"
Title="Journal">
<RichTextBox>
<FlowDocument>
<Paragraph FontSize="14"
FontFamily="Segoe">
This is the content of the Journal Pane.
<LineBreak />
A
<Bold>RichTextBox</Bold> has been added here
</Paragraph>
</FlowDocument>
</RichTextBox>
</xcad:LayoutAnchorable>
</xcad:LayoutAnchorablePane>
</xcad:LayoutAnchorablePaneGroup>
</xcad:LayoutPanel>
<xcad:LayoutRoot.LeftSide>
<xcad:LayoutAnchorSide>
<xcad:LayoutAnchorGroup>
<xcad:LayoutAnchorable Title="Agenda"
ContentId="agenda"
IconSource="..\Images\book_open.png">
<TextBlock Text="Agenda Content"
Margin="10"
FontSize="18"
FontWeight="Black"
TextWrapping="Wrap" />
</xcad:LayoutAnchorable>
<xcad:LayoutAnchorable Title="Contacts"
ContentId="contacts"
IconSource="..\Images\address_book-edit.png">
<TextBlock Text="Contacts Content"
Margin="10"
FontSize="18"
FontWeight="Black"
TextWrapping="Wrap" />
</xcad:LayoutAnchorable>
</xcad:LayoutAnchorGroup>
</xcad:LayoutAnchorSide>
</xcad:LayoutRoot.LeftSide>
</xcad:LayoutRoot>
</xcad:DockingManager>
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Center">
<Button Content="Save AvalonDock"
Margin="5"
Padding="5"
Click="SaveButton_Click" />
<Button Content="Load AvalonDock"
Margin="5"
Padding="5"
Click="LoadButton_Click" />
</StackPanel>
</StackPanel>
</Grid>
</Window>
Get rid of the StackPanel on the second row of the Grid. A StackPanel doesn't resize its children.
Also note that the default values of the HorizontalAlignment and the VerticalAlignment of a Grid are both Stretch so you don't need to set these explicitly.
Try this:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="Usage:" Style="{StaticResource Header}" />
<xcad:DockingManager x:Name="_dockingManager"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
AllowMixedOrientation="True"
Grid.Row="1"
BorderBrush="Gray"
BorderThickness="1">
<xcad:DockingManager.DocumentHeaderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding IconSource}"
Margin="0,0,4,0" />
<TextBlock Text="{Binding Title}" />
</StackPanel>
</DataTemplate>
</xcad:DockingManager.DocumentHeaderTemplate>
<xcad:LayoutRoot x:Name="_layoutRoot">
<xcad:LayoutPanel Orientation="Horizontal">
<xcad:LayoutAnchorablePane DockWidth="200">
<xcad:LayoutAnchorable ContentId="properties"
Title="Properties"
CanHide="False"
CanClose="False"
AutoHideWidth="240"
IconSource="..\Images\table-gear.png">
<xctk:PropertyGrid NameColumnWidth="110"
SelectedObject="{Binding ElementName=_layoutRoot, Path=LastFocusedDocument.Content}"
AutoGenerateProperties="False">
<xctk:PropertyGrid.PropertyDefinitions>
<xctk:PropertyDefinition TargetProperties="Background" />
<xctk:PropertyDefinition TargetProperties="BorderBrush" />
<xctk:PropertyDefinition TargetProperties="BorderThickness" />
<xctk:PropertyDefinition TargetProperties="FontSize" />
<xctk:PropertyDefinition TargetProperties="FontStyle" />
<xctk:PropertyDefinition TargetProperties="Width" />
<xctk:PropertyDefinition TargetProperties="Height" />
</xctk:PropertyGrid.PropertyDefinitions>
</xctk:PropertyGrid>
</xcad:LayoutAnchorable>
</xcad:LayoutAnchorablePane>
<xcad:LayoutDocumentPaneGroup>
<xcad:LayoutDocumentPane>
<xcad:LayoutDocument ContentId="document1"
Title="Document 1"
IconSource="..\Images\document.png">
<Button Content="Document 1 Content"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</xcad:LayoutDocument>
<xcad:LayoutDocument ContentId="document2"
Title="Document 2"
IconSource="..\Images\document.png">
<TextBox Text="Document 2 Content"
AcceptsReturn="True" />
</xcad:LayoutDocument>
</xcad:LayoutDocumentPane>
</xcad:LayoutDocumentPaneGroup >
<xcad:LayoutAnchorablePaneGroup DockWidth="125">
<xcad:LayoutAnchorablePane>
<xcad:LayoutAnchorable ContentId="alarms"
Title="Alarms"
IconSource="..\Images\alarm.png"
CanClose="True">
<ListBox>
<s:String>Alarm 1</s:String>
<s:String>Alarm 2</s:String>
<s:String>Alarm 3</s:String>
</ListBox>
</xcad:LayoutAnchorable>
<xcad:LayoutAnchorable ContentId="journal"
Title="Journal">
<RichTextBox>
<FlowDocument>
<Paragraph FontSize="14"
FontFamily="Segoe">
This is the content of the Journal Pane.
<LineBreak />
A
<Bold>RichTextBox</Bold> has been added here
</Paragraph>
</FlowDocument>
</RichTextBox>
</xcad:LayoutAnchorable>
</xcad:LayoutAnchorablePane>
</xcad:LayoutAnchorablePaneGroup>
</xcad:LayoutPanel>
<xcad:LayoutRoot.LeftSide>
<xcad:LayoutAnchorSide>
<xcad:LayoutAnchorGroup>
<xcad:LayoutAnchorable Title="Agenda"
ContentId="agenda"
IconSource="..\Images\book_open.png">
<TextBlock Text="Agenda Content"
Margin="10"
FontSize="18"
FontWeight="Black"
TextWrapping="Wrap" />
</xcad:LayoutAnchorable>
<xcad:LayoutAnchorable Title="Contacts"
ContentId="contacts"
IconSource="..\Images\address_book-edit.png">
<TextBlock Text="Contacts Content"
Margin="10"
FontSize="18"
FontWeight="Black"
TextWrapping="Wrap" />
</xcad:LayoutAnchorable>
</xcad:LayoutAnchorGroup>
</xcad:LayoutAnchorSide>
</xcad:LayoutRoot.LeftSide>
</xcad:LayoutRoot>
</xcad:DockingManager>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center">
<Button Content="Save AvalonDock"
Margin="5"
Padding="5"
Click="SaveButton_Click" />
<Button Content="Load AvalonDock"
Margin="5"
Padding="5"
Click="LoadButton_Click" />
</StackPanel>
</Grid>
I am using MaterialDesignInXAML for a WPF application. I have a PopupBox that I want to change the icon for. Currently it defaults to DotsVertical and I would like to have it as a DotsHorizontal.
I tried the following with no luck.
<materialDesign:PopupBox PlacementMode="BottomAndAlignRightEdges" StaysOpen="False">
<materialDesign:PopupBox.Content>
<materialDesign:PackIcon Kind="DotsHorizontal" />
</materialDesign:PopupBox.Content>
<StackPanel>
<TextBlock Text="Test1" />
<TextBlock Text="Test2" />
<TextBlock Text="Test3" />
</StackPanel>
</materialDesign:PopupBox>
Thanks in advance!
Figured it out and will leave an answer here in case anyone else comes across this issue. There is a property called ToggleContent
<materialDesign:PopupBox PlacementMode="BottomAndAlignRightEdges" StaysOpen="False">
<materialDesign:PopupBox.ToggleContent>
<materialDesign:PackIcon Kind="DotsHorizontal" />
</materialDesign:PopupBox.ToggleContent>
<StackPanel>
<TextBlock Text="Test1" />
<TextBlock Text="Test2" />
<TextBlock Text="Test3" />
</StackPanel>
</materialDesign:PopupBox>
In order to change the Icon and preserve the current style use this:
<materialDesign:PopupBox PlacementMode="BottomAndAlignRightEdges" StaysOpen="False">
<materialDesign:PopupBox.ToggleContent>
<materialDesign:PackIcon Kind="DotsHorizontal"
Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=materialDesign:PopupBox}, Path=Foreground}" />
</materialDesign:PopupBox.ToggleContent>
<StackPanel>
<TextBlock Text="Test1" />
<TextBlock Text="Test2" />
<TextBlock Text="Test3" />
</StackPanel>
</materialDesign:PopupBox>
This is my entire usercontrol xaml:
Problem:The Combobox inside DataGrid named DG_Prices has a DataTemplate whose contentcontrol contains a Combobox.The ItemSource of this ComboBox is bound to a public property in Code Behind named LstAllPrices.ItemSource is not binding to to property named LstAllPrices which is a public property in code behind.
<UserControl x:Class="Hexa.Screens.FrmItemDetail"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Hexa.Screens"
mc:Ignorable="d"
Height="535" Width="605">
<UserControl.Resources>
<Style x:Key="TextBlockStyle" TargetType="{x:Type Border}">
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="BorderBrush" Value="Beige"/>
</Style>
<Style TargetType="Label">
<Setter Property="FontFamily" Value="Times new Roman"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Foreground" Value="DarkBlue"/>
</Style>
<Style TargetType="GroupBox">
<Setter Property="Margin" Value="25,1,5,5"/>
<Setter Property="Background" Value="LightGray"/>
<Setter Property="BorderBrush" Value="#25A0DA"/>
<Setter Property="BorderThickness" Value="0.5,0.4,0.4,0.4"/>
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}" FontWeight="Bold" FontStyle="Italic" FontFamily="Palatino Linotype" FontSize="14" Foreground="DarkRed" />
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Name="Style_TextBox" TargetType="TextBox">
<Setter Property="BorderBrush" Value="SkyBlue"/>
<Setter Property="Background" Value="White"/>
<Setter Property="FontFamily" Value="Times New Roman"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Height" Value="20"/>
</Style>
</UserControl.Resources>
<Canvas HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="-315,-70">
<TabControl HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Height="606" Width="1233" Canvas.Left="0" Background="LightGray">
<TabItem Header="Main Information">
<Canvas Height="400" Width="590" Margin="0,0,0,0">
<Label Content="Code:" Canvas.Left="-198" Canvas.Top="-75"/>
<Image Source="/Hexa;component/Images/SEARCH.png" Width="25" Height="18" Canvas.Top="-72" Canvas.Left="-76" />
<Button Content="Filter" Canvas.Top="-74" Width="105" FontWeight="Bold" Canvas.Left="-313" FontStyle="Italic"/>
<Label Content="Creation Date:" Canvas.Top="-79" Canvas.Left="717" />
<Label Content="POS menu Filter:" Canvas.Top="-79" Canvas.Left="285" />
<Label Content="Production Date:" Canvas.Top="-81" Canvas.Left="505" />
<DatePicker Width="100" Canvas.Left="607" Canvas.Top="-81" x:Name="Dt_Prod_Date" />
<Label Content="Expiry Date:" Canvas.Top="-51" Canvas.Left="507" />
<DatePicker Width="100" Canvas.Left="608" Canvas.Top="-52" x:Name="Dt_Expiry_Date" />
<TextBox x:Name="txtPosMenuFilter" Width="115" Canvas.Top="-78" Canvas.Left="385"/>
<Border Style="{StaticResource TextBlockStyle}" Canvas.Top="-72" Canvas.Left="830">
<TextBlock Width="70" Canvas.Top="-40" Canvas.Left="-188" x:Name="txtCreationDate" Height="16" Background="White" />
</Border>
<Label Content="Last Updation Date:" Canvas.Top="-53" Canvas.Left="716" />
<Border Style="{StaticResource TextBlockStyle}" Canvas.Top="-46" Canvas.Left="830" >
<TextBlock Width="70" Canvas.Top="-40" Canvas.Left="-188" x:Name="txtUpdateDate" Height="16" Background="White" />
</Border>
<Button Content="Generate Code" Canvas.Top="-74" Background="Azure" Width="105" FontWeight="Bold" Canvas.Left="-38"/>
<TextBox x:Name="txtAutoGen_Code" Width="79" Height="17" Background="White" Canvas.Top="-72" Canvas.Left="-158" />
<GroupBox Header="Button Properties" Height="285" Width="594" Margin="0" Canvas.Top="-32" Canvas.Left="-313">
<Canvas>
<Label Content="Ticket description:" Margin="4,1,409,150" />
<TextBox x:Name="txtDesc1" Width="195" Canvas.Left="115" Canvas.Top="7" LostFocus="txtDesc1_LostFocus"/>
<Label Content="Second description:" Canvas.Left="3" Canvas.Top="27" />
<Label Content="Button sequence:" Canvas.Left="3" Canvas.Top="59" />
<ComboBox x:Name="cmbItem_Item_touch_scr_seq_2" Height="22" Canvas.Left="115" Canvas.Top="61" Width="46">
<ComboBoxItem Content="1"/>
<ComboBoxItem Content="2"/>
<ComboBoxItem Content="3"/>
<ComboBoxItem Content="4"/>
<ComboBoxItem Content="5"/>
</ComboBox>
<Label Content="UOM:" Canvas.Left="174" Canvas.Top="61" />
<ComboBox x:Name="cmbUOM" Width="92" Canvas.Left="218" Canvas.Top="62"/>
<TextBox x:Name="txtDesc2" Width="195" Canvas.Left="115" Canvas.Top="31"/>
<Label Content="Button Template Settings:" Canvas.Left="28" Canvas.Top="102" />
<Label Content="Name:" Width="56" Height="30" Canvas.Left="93" Canvas.Top="127"/>
<TextBox x:Name="txtItem_Name1" HorizontalAlignment="Right" Width="142" MaxLength="15" Text="NAME-1" Height="22" Canvas.Left="153" Canvas.Top="130" />
<TextBox x:Name="txtItem_Name2" HorizontalAlignment="Left" Width="142" MaxLength="15" Text="NAME-2" Height="22" Canvas.Left="153" Canvas.Top="158"/>
<Label Content="BackColor:" Margin="0" HorizontalAlignment="Left" Width="77" Height="25" Canvas.Left="26" Canvas.Top="187"/>
<local:UsrColorPicker x:Name="cmbItem_Item_back_color" HorizontalAlignment="Center" Width="224" Height="22" SettingConfirmed="cmbItem_Item_back_color_SettingConfirmed" Canvas.Left="101" Canvas.Top="187" />
<Label Content="ForeColor:" Margin="0" Height="24" Canvas.Left="26" Canvas.Top="219" Width="75"/>
<local:UsrColorPicker x:Name="cmbItem_Item_Fore_Color" HorizontalAlignment="Right" Width="223" Height="22" SettingConfirmed="cmbItem_Item_Fore_Color_SettingConfirmed" Canvas.Left="102" Canvas.Top="219" />
<GroupBox Height="241" Width="237" Background="DarkGray" Canvas.Left="336" Margin="0" Header="Button Template" Canvas.Top="1">
<Canvas>
<Button Canvas.Left="42" Canvas.Top="29" Width="145" Height="150" x:Name="cmdButtonTemplate" Click="cmdButtonTemplate_Click" Style="{StaticResource MyButton}">
<ContentControl HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Height="131" Canvas.Left="10" Canvas.Top="10" Width="142" >
<Canvas x:Name="ContentCanvas">
<Image Canvas.Top="5" Canvas.Left="5" x:Name="Button_Image" />
<TextBlock Canvas.Left="50" Canvas.Top="10" Text="{Binding Text, ElementName=txtItem_Name1}" Width="auto" x:Name="Button_Text_1"/>
<TextBlock Canvas.Left="50" Canvas.Top="70" Text="{Binding Text, ElementName=txtItem_Name2}" Width="auto" x:Name="Button_Text_2"/>
</Canvas>
</ContentControl>
</Button>
</Canvas>
</GroupBox>
</Canvas>
</GroupBox>
<GroupBox Height="109" Width="254" Margin="0" Header="Groups/Categories" Canvas.Top="252" Canvas.Left="-315">
<Canvas>
<Label Content="Group" Canvas.Top="12" Width="43" Canvas.Left="2"/>
<ComboBox x:Name="cmbGroupCode" Width="48" Canvas.Left="55" Canvas.Top="13" />
<TextBox x:Name="txtGroupName" Width="105" Canvas.Left="106" Canvas.Top="13" IsReadOnly="True"/>
<Image Source="/Hexa;component/Images/SEARCH.png" Width="25" Height="18" Canvas.Left="213" Canvas.Top="15" x:Name="cmdSearchGroup" />
<Label Content="Category" Canvas.Top="48" Width="57" Canvas.Left="-1"/>
<ComboBox x:Name="cmbCategoryCode" Width="48" Canvas.Left="55" Canvas.Top="48" />
<TextBox x:Name="txtCategoryName" Width="105" Canvas.Left="106" Canvas.Top="48" IsReadOnly="True"/>
<Image Source="/Hexa;component/Images/SEARCH.png" Width="25" Height="18" Canvas.Left="212" Canvas.Top="49" x:Name="cmdSearchCategory" />
</Canvas>
</GroupBox>
<GroupBox Height="109" Width="111" Margin="0" Canvas.Top="252" Header="Bonus Schema" Canvas.Left="-58">
<Canvas>
<Label Content="Amount:" Canvas.Top="1" Width="55" Canvas.Left="9"/>
<TextBox x:Name="txtBonusAmount" Width="76" Canvas.Left="12" Canvas.Top="22"/>
<Label Content="Bonus:" Canvas.Top="38" Width="43" Canvas.Left="10"/>
<TextBox x:Name="txtBonus" Width="76" Canvas.Left="13" Canvas.Top="58"/>
</Canvas>
</GroupBox>
<GroupBox Width="226" Height="109" Margin="0" Canvas.Top="252" Header="Modifiers" Canvas.Left="55">
<Canvas>
<TextBox x:Name="txtModCode1" Width="48" Canvas.Left="2" Canvas.Top="1" Height="17"/>
<TextBox x:Name="txtModname1" Width="119" Canvas.Left="60" Canvas.Top="1" Height="17"/>
<Image Source="/Hexa;component/Images/SEARCH.png" Width="25" Height="18" Canvas.Left="183" Canvas.Top="3" x:Name="cmdSearchMod1" />
<TextBox x:Name="txtModCode2" Width="48" Canvas.Left="2" Canvas.Top="23" Height="17"/>
<TextBox x:Name="txtModname2" Width="117" Canvas.Left="60" Canvas.Top="23" Height="17"/>
<Image Source="/Hexa;component/Images/SEARCH.png" Width="25" Height="18" Canvas.Left="182" Canvas.Top="26" x:Name="cmdSearchMod2" />
<TextBox x:Name="txtModCode3" Width="48" Canvas.Left="2" Canvas.Top="45" Height="17"/>
<TextBox x:Name="txtModname3" Width="117" Canvas.Left="60" Canvas.Top="45" Height="17"/>
<Image Source="/Hexa;component/Images/SEARCH.png" Width="25" Height="18" Canvas.Left="182" Canvas.Top="47" x:Name="cmdSearchMod3" />
<TextBox x:Name="txtModCode4" Width="48" Canvas.Left="2" Canvas.Top="66" Height="17"/>
<TextBox x:Name="txtModname4" Width="116" Canvas.Left="60" Canvas.Top="66" Height="17"/>
<Image Source="/Hexa;component/Images/SEARCH.png" Width="25" Height="18" Canvas.Left="182" Canvas.Top="67" x:Name="cmdSearchMod4" />
</Canvas>
</GroupBox>
<GroupBox Height="126" Width="596" Margin="0" Canvas.Top="356" Canvas.Left="-315" Header="Pricing">
<DataGrid VerticalScrollBarVisibility="Visible" x:Name="Dg_Prices" CanUserReorderColumns="True" CanUserResizeColumns="False" CanUserResizeRows="False" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Price name">
<DataGridTemplateColumn.CellTemplate >
<DataTemplate>
<DataGridCell>
<ContentControl>
<ComboBox DataContext="{Binding RelativeSource={RelativeSource Self}}"
ItemsSource="{Binding LstAllPrices}"
/>
</ContentControl>
</DataGridCell>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Price Point">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DataGridCell>
<ContentControl>
<TextBox Width="100" Text="{Binding PriceName}" x:Name="AmountColumn" />
</ContentControl>
</DataGridCell>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</GroupBox>
<GroupBox Height="125" Width="620" Canvas.Left="285" Margin="0" Header="Inventory Information" Canvas.Top="-33">
<Canvas Margin="3,0,-3,0">
<Label Content="Supplier:" Canvas.Left="8" Canvas.Top="-2" />
<TextBox x:Name="txtSupplierId" Width="62" Canvas.Left="115" Canvas.Top="1"/>
<TextBox x:Name="txtSupplierName" Width="340" Canvas.Left="191" Canvas.Top="1"/>
<Image Source="/Hexa;component/Images/SEARCH.png" Width="25" Height="18" Canvas.Left="533" Canvas.Top="2" />
<Label Content="Purchase price:" Canvas.Top="22" Canvas.Left="7" />
<TextBox x:Name="txtSupplierPrice" Width="62" Canvas.Left="115" Canvas.Top="25"/>
<Label Content="VAT Code:" Canvas.Top="25" Canvas.Left="263" />
<TextBox x:Name="txtSupplierVAT" Width="90" Canvas.Left="372" Canvas.Top="25"/>
<Image Source="/Hexa;component/Images/SEARCH.png" Width="25" Height="18" Canvas.Left="469" Canvas.Top="26" />
<Label Content="15.00%" Canvas.Top="24" Width="51" Canvas.Left="491" FontWeight="Thin" x:Name="lblSupplier_Vat_Percentage"/>
<Label Content="Average Cost price:" Canvas.Top="48" Canvas.Left="5" />
<Label Content="Quantity in hand:" Canvas.Top="49" Canvas.Left="261" />
<TextBox x:Name="txtAvgCostPrice" Width="62" Canvas.Left="115" Canvas.Top="49"/>
<TextBox x:Name="txtCurrent_Qty" Width="55" Canvas.Left="373" Canvas.Top="49"/>
<Label Content="Minimum Stock:" Canvas.Top="75" Canvas.Left="6" />
<TextBox x:Name="txtMinStock" Width="62" Canvas.Left="115" Canvas.Top="74"/>
<Label Content="Maximum Stock:" Canvas.Top="73" Canvas.Left="262" />
<TextBox x:Name="txtMaxStock" Width="90" Canvas.Left="373" Canvas.Top="74"/>
</Canvas>
</GroupBox>
<GroupBox Height="166" Width="619" Canvas.Left="286" Margin="0" Canvas.Top="89" Header="Offers">
<Canvas>
<GroupBox Height="153" Width="191" Margin="0" Canvas.Top="-14" >
<Canvas Margin="0,0,0,-16">
<Label Content="Line discount" Canvas.Left="-3" Canvas.Top="-9"/>
<TextBox x:Name="txtLineDiscount" Width="76" Canvas.Left="77" Canvas.Top="-5" MaxLength="14"/>
<Label Content="Beginning:" Canvas.Top="18" Canvas.Left="11"/>
<DatePicker Width="100" Canvas.Left="77" Canvas.Top="19" x:Name="Dt_line_Disc_Begin_Date" />
<Label Content="Till:" Canvas.Top="46" Canvas.Left="11"/>
<DatePicker Width="100" Canvas.Left="77" Canvas.Top="48" x:Name="Dt_line_Disc_End_Date" />
<Label Content="Future selling price:" Canvas.Top="74" Canvas.Left="11"/>
<TextBox x:Name="txtFuture_Price_Sell" Width="53" Canvas.Left="124" Canvas.Top="77"/>
<Label Content="Activate on:" Canvas.Top="102" Canvas.Left="9"/>
<DatePicker Width="99" Canvas.Left="78" Canvas.Top="101" x:Name="Dt_line_Disc_Activation_Date" />
</Canvas>
</GroupBox>
<GroupBox Height="153" Width="412" Canvas.Left="195" Margin="0" Canvas.Top="-14" >
<Canvas>
<Label Content="Specific time price:" Canvas.Left="-3" Canvas.Top="3"/>
<TextBox x:Name="txtFuture_Selling_Price" Width="62" Canvas.Left="124" Canvas.Top="5"/>
<Label Content="Activate on:" Canvas.Left="215" Canvas.Top="3"/>
<DatePicker Width="99" Canvas.Left="296" Canvas.Top="3" x:Name="Dt_Spec_Time_Price_Activation_Date" />
<Label Content="Price on specific hours:" Canvas.Left="-3" Canvas.Top="31"/>
<TextBox x:Name="txtSpecific_Hour_Price" Width="61" Canvas.Left="125" Canvas.Top="31"/>
<Label Content="From Time:" Canvas.Left="-3" Canvas.Top="69"/>
<ComboBox x:Name="cmb_Specific_Time_Price_From_Hour" Canvas.Top="71" Canvas.Left="67"/>
<ComboBox x:Name="cmb_Specific_Time_Price_From_Minute" Canvas.Top="71" Canvas.Left="94"/>
<Label Content="Till Time:" Canvas.Top="99" Canvas.Left="-3"/>
<ComboBox x:Name="cmb_Specific_Time_Price_Till_Hour" Canvas.Top="99" Canvas.Left="68"/>
<ComboBox x:Name="cmb_Specific_Time_Price_Till_Minute" Canvas.Top="99" Canvas.Left="95"/>
<Label Content="Order Qty:" Canvas.Top="70" Canvas.Left="136"/>
<TextBox x:Name="txtOrder_Qty" Width="47" Canvas.Left="200" Canvas.Top="72"/>
<Label Content="Free Qty:" Canvas.Top="97" Canvas.Left="137"/>
<TextBox x:Name="txtFree_Qty" Width="47" Canvas.Left="200" Canvas.Top="99"/>
<Label Content="From:" Canvas.Top="71" Canvas.Left="257"/>
<DatePicker Width="99" Canvas.Left="298" Canvas.Top="69" x:Name="Dt_Specific_Time_Price_From_Date" />
<Label Content="Till:" Canvas.Top="98" Canvas.Left="259"/>
<DatePicker Width="99" Canvas.Left="298" Canvas.Top="97" x:Name="Dt_Specific_Time_Price_Till_Date" />
</Canvas>
</GroupBox>
</Canvas>
</GroupBox>
<GroupBox Height="228" Width="327" Canvas.Left="286" Margin="0" Canvas.Top="253" Header="Miscelleneous Options">
<Canvas>
<Label Content="OUT of Sales Panel" Canvas.Top="12" Canvas.Left="7"/>
<CheckBox x:Name="chkOut_Of_Sales" Canvas.Left="138" Canvas.Top="18"/>
<Label Content="OUT of STOCK Panel" Canvas.Top="53" Canvas.Left="6" />
<CheckBox x:Name="chkOut_Of_Stock" Canvas.Left="291" Canvas.Top="19"/>
<Label Content="Open price" Canvas.Top="12" Canvas.Left="192" />
<CheckBox x:Name="chkOpen_Price" Canvas.Left="138" Canvas.Top="57"/>
<Label Content="Open Description" Canvas.Top="81" Canvas.Left="190" />
<CheckBox x:Name="chkOpenDesc" Canvas.Left="291" Canvas.Top="54"/>
<Label Content="Non Stock" Canvas.Top="48" Canvas.Left="192" />
<CheckBox x:Name="chkNon_Stock" Canvas.Left="138" Canvas.Top="91"/>
<Label Content="Weighable" Canvas.Top="87" Canvas.Left="5" />
<CheckBox x:Name="chkWeighable" Canvas.Left="292" Canvas.Top="87"/>
<Label Content="No Discount" Canvas.Top="116" Canvas.Left="195" />
<CheckBox x:Name="chkNo_Discount" Canvas.Left="293" Canvas.Top="121"/>
<Label Content="Show price on button" Canvas.Top="123" Canvas.Left="5" />
<CheckBox x:Name="chkShow_Price_On_Button" Canvas.Left="138" Canvas.Top="128"/>
<Label Content="Modification AutoOpen" Canvas.Top="161" Canvas.Left="6" />
<CheckBox x:Name="chkModification_Auto_Open" Canvas.Left="138" Canvas.Top="167"/>
</Canvas>
</GroupBox>
<GroupBox Height="217" Width="287" Canvas.Left="618" Margin="0" Canvas.Top="255" Header="Active Printer">
<Canvas>
<ListBox x:Name="lstprinters" Height="190" Width="275" FontFamily="Sans Serif" FontSize="22">
<ListBoxItem Content="Printer-1"/>
<ListBoxItem Content="Printer-2"/>
<ListBoxItem Content="Printer-3"/>
<ListBoxItem Content="Printer-4"/>
<ListBoxItem Content="Printer-5"/>
<ListBoxItem Content="Printer-6"/>
<ListBoxItem Content="Printer-7"/>
<ListBoxItem Content="Printer-8"/>
</ListBox>
</Canvas>
</GroupBox>
</Canvas>
</TabItem>
</TabControl>
<Image Source="..\Images\FIRST-RECORD.png" Height="55" Width="55" Canvas.Top="615" Canvas.Left="317" />
<Image Source="..\Images\PREVIOUS_RECORD.png" Height="55" Width="55" Canvas.Top="615" Canvas.Left="384" />
<Image Source="..\Images\NEXT_RECORD.png" Height="55" Width="55" Canvas.Top="615" Canvas.Left="448" />
<Image Source="..\Images\LAST_RECORD.png" Height="55" Width="55" Canvas.Top="615" Canvas.Left="515" />
<Image Source="..\Images\ADD_RECORD.png" Height="55" Width="55" Canvas.Top="615" Canvas.Left="598" />
<Image Source="..\Images\edit.png" Height="55" Canvas.Top="615" Canvas.Left="660" />
<Image Source="..\Images\delete.png" Height="55" Width="55" Canvas.Top="615" Canvas.Left="723" />
<Image Source="..\Images\save.png" Height="55" Width="55" Canvas.Top="615" Canvas.Left="811" x:Name="cmdSave" MouseUp="cmdSave_MouseUp" />
<Image Source="..\Images\edit.png" Height="55" Width="55" Canvas.Top="615" Canvas.Left="874" />
<Image Source="..\Images\exit.png" Height="55" Width="55" x:Name="cmdExit" MouseUp="cmdExit_MouseUp" Canvas.Left="937" Canvas.Top="615"/>
</Canvas>
code behind is:
using Hexa.Global;
using Hexa.ViewModels;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WPF.MDI;
namespace Hexa.Screens
{
public partial class FrmItemDetail : UserControl
{
DC_ItemDetails DCIM;
private List<string> _LstAllPrices;
public List<string> LstAllPrices
{
get
{
if (_LstAllPrices == null)
{
_LstAllPrices = new List<string>();
_LstAllPrices = DCIM.Lst_Prices.Select(item => item.PriceName).ToList<string>();
}
return _LstAllPrices;
}
set
{
if(_LstAllPrices==null)
{
_LstAllPrices = value;
}
}
}
public FrmItemDetail()
{
InitializeComponent();
DCIM = new DC_ItemDetails();
this.DataContext = DCIM;
cmbGroupCode.ItemsSource = DCIM.Lst_Button_Details.Where(item => item.Button_Template_Type.Equals("Group", StringComparison.Ordinal)).Select(item => item.Button_Template_Id).ToList<int>();
cmbUOM.ItemsSource = DCIM.Lst_UOM.Select(item => item.UOM).ToList<string>();
Dg_Prices.ItemsSource = this.DCIM.Lst_Prices;
}
}
}
Getting following error in output window:
System.Windows.Data Error: 40 : BindingExpression path error: 'LstAllPrices' property not found on 'object' ''ListView' (Name='')'. BindingExpression:Path=LstAllPrices; DataItem='ListView' (Name=''); target element is 'ListView' (Name=''); target property is 'ItemsSource' (type 'IEnumerable')
If MyList is a public property of the parent UserControl that returns a List<string>, you should be able to bind to it like this:
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding MyList, RelativeSource={RelativeSource AncestorType=UserControl}}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
I have 4 IntegerUpDowns from the Xceed toolkit. The problem is that the navigation through Tab button does not work at all. I set TabIndex, TabStop properties, but no effect. Maybe somebody had this problem? Any help will be appreciate! Thanks a lot!
Here is a code:
<GroupBox Margin="20"
HorizontalAlignment="Center"
Header="groupbox header text">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0"
Margin="7"
Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" Text="text1:" />
<xctk:IntegerUpDown Name="updown1"
Width="50"
Height="25"
Margin="17,0,30,0"
TabIndex="0"
IsTabStop="True"
VerticalAlignment="Center"
Increment="1"
PreviewKeyDown="NumericUpDown_OnPreviewKeyDown"
ValueChanged="Updown1_OnValueChanged"
Value="{Binding Property1,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" />
<TextBlock VerticalAlignment="Center" Text="text2" />
<xctk:IntegerUpDown Name="updown2"
Width="50"
Height="25"
Margin="43,0,0,0"
VerticalAlignment="Center"
Increment="2"
TabIndex="2"
IsTabStop="True"
PreviewKeyDown="NumericUpDown_OnPreviewKeyDown"
Value="{Binding Property2,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
<StackPanel Grid.Row="1"
Margin="7,0,7,7"
Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" Text="text3:" />
<xctk:IntegerUpDown Name="updown3"
Width="50"
Height="25"
Margin="7,0,30,0"
VerticalAlignment="Center"
Increment="1"
TabIndex="1"
IsTabStop="True"
PreviewKeyDown="NumericUpDown_OnPreviewKeyDown"
ValueChanged="Updown3_OnValueChanged"
Value="{Binding Proeprty3,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" />
<TextBlock VerticalAlignment="Center" Text="text4:"/>
<xctk:IntegerUpDown Name="updown4"
Width="50"
Height="25"
Margin="7,0,0,0"
TabIndex="3"
VerticalAlignment="Center"
Increment="1"
IsTabStop="True"
PreviewKeyDown="NumericUpDown_OnPreviewKeyDown"
Value="{Binding Property4,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
</Grid>
</GroupBox>
If I have a Horizontal StackPanel with many elements, with different margin between them:
Is there any difference if I give each element a left margin or
is there some advantage giving every second element a right and left margin - that way only one element gets its margin property set.
<StackPanel Orientation="Horizontal">
<TextBlock Name="textblock1" />
<TextBlock Name="textblock2" Margin="5,0,0,0" />
<TextBlock Name="textblock3" Margin="10,0,0,0" />
...
</StackPanel>
or
<StackPanel Orientation="Horizontal">
<TextBlock Name="textblock1" />
<TextBlock Name="textblock2" Margin="5,0,10,0" />
<TextBlock Name="textblock3" />
...
</StackPanel>
I was just wondering if there was a best-practise concerning this.
If the Margin is the same for every element, you can factor it out in a style:
<StackPanel Orientation="Horizontal">
<StackPanel.Resources>
<Style TargetType="TextBlock>
<Setter Property="Margin" Value="5,0,0,0" />
</Style>
</StackPanel.Resources>
<TextBlock Name="textblock1" />
<TextBlock Name="textblock2" />
<TextBlock Name="textblock3" />
...
</StackPanel>
Other than that it makes no difference.