Collapse/Expand Groupboxes - wpf

I have the following XAML, in which there are three group boxes stacked. In the header of those groupboxes are checkboxes.
What I'd like to achieve : when I check/uncheck a box, I'd like the corresponding groupbox to slowly expand/collapse, with a smooth animation.
I'm trying this in Blend 4 but am quite a newbie. Any help on how to achieve this ? In particular, can the animation be self-contained in the XAML ?
UPDATE : This seems to come close , but I don't quite get it
<UserControl
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"
mc:Ignorable="d"
x:Class="WpfControlLibrary1.MainControl"
x:Name="MultiVol">
<StackPanel x:Name="LayoutRoot" HorizontalAlignment="Stretch">
<GroupBox Margin="8,0" BorderBrush="#FF88B1D8">
<GroupBox.Header>
<WrapPanel>
<CheckBox IsChecked="True" VerticalAlignment="Center" />
<Label Content="Volatility" Background="#00000000" Foreground="#FF0033FF" FontWeight="Bold" FontFamily="/WpfControlLibrary1;component/Fonts/#Tahoma" />
</WrapPanel>
</GroupBox.Header>
<UniformGrid Columns="2">
<Label Content="Spots"></Label>
<TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
<Label Content="Hist. references" />
<TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
<Label Content="Tenors" />
<TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
</UniformGrid>
</GroupBox>
<GroupBox Margin="8,0" BorderBrush="#FF88B1D8">
<GroupBox.Header>
<WrapPanel>
<CheckBox IsChecked="True" VerticalAlignment="Center" />
<Label Content="Skew" Background="#00000000" Foreground="#FF0033FF" FontWeight="Bold" FontFamily="/WpfControlLibrary1;component/Fonts/#Tahoma" />
</WrapPanel>
</GroupBox.Header>
<UniformGrid Columns="2">
<Label Content="Spot Intervals"></Label>
<TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
<Label Content="Hist. references" />
<TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
<Label Content="Tenors" />
<TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
<Label Content="Compute 'Power'" />
<CheckBox IsChecked="False" VerticalAlignment="Center"/>
</UniformGrid>
</GroupBox>
<GroupBox Margin="8,0" BorderBrush="#FF88B1D8">
<GroupBox.Header>
<WrapPanel>
<CheckBox IsChecked="True" VerticalAlignment="Center" />
<Label Content="Term structure" Background="#00000000" Foreground="#FF0033FF" FontWeight="Bold" FontFamily="/WpfControlLibrary1;component/Fonts/#Tahoma" />
</WrapPanel>
</GroupBox.Header>
<UniformGrid Columns="2">
<Label Content="Spots" />
<TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
<Label Content="Tenors" />
<TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
</UniformGrid>
</GroupBox>
</StackPanel>
</UserControl>

Just edited the first group box in your simple code:
<GroupBox Margin="8,0" BorderBrush="#FF88B1D8" Height="150">
<GroupBox.Resources>
<Style TargetType="GroupBox">
<Style.Triggers>
<EventTrigger RoutedEvent="CheckBox.Unchecked">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Height" Duration="0:0:.2" To="30" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="CheckBox.Checked">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Height" Duration="0:0:.2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
</GroupBox.Resources>
<GroupBox.Header>
<WrapPanel>
<CheckBox IsChecked="True" VerticalAlignment="Center" />
<Label Content="Volatility" Background="#00000000" Foreground="#FF0033FF" FontWeight="Bold" />
</WrapPanel>
</GroupBox.Header>
<UniformGrid Columns="2">
<Label Content="Spots"></Label>
<TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
<Label Content="Hist. references" />
<TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
<Label Content="Tenors" />
<TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
</UniformGrid>
</GroupBox>
If you want to have this on a single group box you could place the Style Element inside this code
<GroupBox.Resources>
<!--Style Inside HEre-->
</GroupBox.Resources>
to implement it on a single group box.
Another suggestion is created a Style inside the stack panel and add a key to it:
<StackPanel.Resources>
<Style TargetType="GroupBox" x:Key="groupBoxStyle">
<Style.Triggers>
<EventTrigger RoutedEvent="CheckBox.Unchecked">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Height" Duration="0:0:.2" To="30" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="CheckBox.Checked">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Height" Duration="0:0:.2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
</StackPanel.Resources>
then attached it to the style of the groupbox:
<GroupBox Margin="8,0" Height="150" BorderBrush="Transparent" Style="{StaticResource groupBoxStyle}">
<GroupBox.Header>
<WrapPanel>
<CheckBox IsChecked="True" VerticalAlignment="Center" />
<Label Content="Volatility" Background="#00000000" Foreground="#FF0033FF" FontWeight="Bold" />
</WrapPanel>
</GroupBox.Header>
<Border BorderBrush="Black" BorderThickness="2">
<UniformGrid Columns="2">
<Label Content="Spots"></Label>
<TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
<Label Content="Hist. references" />
<TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
<Label Content="Tenors" />
<TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
</UniformGrid>
</Border>
</GroupBox>
this approach will be more useful when you want to implement this on the future to multiple groupboxes
In Case you want to handle the checkbox and unchecked event you could use this code
<GroupBox Margin="8,0" Height="150" BorderBrush="Transparent" Style="{StaticResource groupBoxStyle}" CheckBox.Checked="CheckBox_Checked" CheckBox.Unchecked="CheckBox_Unchecked">
<GroupBox.Header>
<WrapPanel>
<CheckBox x:Name="chkHeader" IsChecked="True" VerticalAlignment="Center" />
<Label Content="Volatility" Background="#00000000" Foreground="#FF0033FF" FontWeight="Bold" />
</WrapPanel>
</GroupBox.Header>
<Border BorderBrush="Black" BorderThickness="2">
<UniformGrid Columns="2">
<Label Content="Spots"></Label>
<TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
<Label Content="Hist. references" />
<TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
<Label Content="Tenors" />
<TextBox AcceptsReturn="False" AcceptsTab="True" AllowDrop="True" IsTabStop="True" />
</UniformGrid>
</Border>
</GroupBox>
and add this in the code behind:
private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
if ((e.OriginalSource as CheckBox).Name != "chkHeader")
{
e.Handled = true;
}
}
private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
{
if ((e.OriginalSource as CheckBox).Name != "chkHeader")
{
e.Handled = true;
}
}

You probably should use an Expander for this (that's what they are for) and animate that.
If you don't like the look re-template them, you can make them look like a group-box.

Related

AvalonDock: How to auto-resize the control?

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>

How to set itemsource of combobox located inside a DataGridTemplateColumn.CellTemplate of WPF?

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>

How to disable the date picker on "cancil" button click

I am learning wpf and xaml. And I want to disable the showing of date picker when cancil button is clicked. How can I achieve that in XAML using style. So when the red cancil button is clicked I want to hide or disable the date picker. Please help me.
Below is what I have till now
<UserControl x:Class="ucWorkOrderActivity"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" Height="74" Width="570" Background="White" BorderBrush="Gray" BorderThickness="1" Loaded="UserControl_Loaded" MouseDoubleClick="UserControl_MouseDoubleClick">
<Grid>
<DockPanel Name="dkpControl" Margin="10,0,25,0" >
<StackPanel Name="stpMoveButtons" Orientation="Vertical" DockPanel.Dock="Right" HorizontalAlignment="Right" Margin="5,0,0,0">
<Button Name="btnUp" Click="btnUp_Click" Height="25" Width="25" Content="▲" ToolTip="Move Action Up" IsEnabled="{Binding Path=IsUpEnabled}" Margin="0,5,5,10" />
<Button Name="btnDown" Click="btnDown_Click" Height="25" Width="25" Content="▼" ToolTip="Move Action Down" Margin="0,0,5,10" IsEnabled="{Binding Path=IsDownEnabled}" />
</StackPanel>
<DockPanel DockPanel.Dock="Top" Margin="0,0,5,0" >
<TextBlock Name="txbDesc" Text="{Binding Path=Description}" Width="150" TextTrimming="CharacterEllipsis" Margin="10,5,5,5" VerticalAlignment="Top" />
<DockPanel Margin="5,0" HorizontalAlignment="Right" DockPanel.Dock="Right" Width="358" >
<TextBlock Name="txbCostLabel" Text="Cost: " DockPanel.Dock="Left" VerticalAlignment="Top" Margin="46,5,0,5" />
<TextBlock Name="txbCost" Text="{Binding Path=AmountCharged}" TextAlignment="Right" DockPanel.Dock="Left" Width="50" Margin="5" VerticalAlignment="Top" />
<DatePicker Name="dtpCompleted" DockPanel.Dock="Right" Height="25" VerticalAlignment="Top" Margin="0,1,0,0" SelectedDate="{Binding Path=EndDate}" Width="90" />
<TextBlock Name="txbStatus" Text="{Binding Path=Status}" DockPanel.Dock="right" HorizontalAlignment="Left" Width="60" Margin="45,5,30,5" TextAlignment="Left" VerticalAlignment="Top" />
</DockPanel>
</DockPanel>
<DockPanel DockPanel.Dock="Bottom" Margin="0,0,5,0" >
<Image Name="imgLocationChange" Margin="25,0" DockPanel.Dock="Left" Height="24" Source="/SMS_Main;component/Resources/UnitMoveLoc_24.png" Visibility="Hidden" />
<TextBlock Name="txbCharge" Text="{Binding Path=ChargeWhen}" Margin="70,0,0,0" VerticalAlignment="Center" />
<Button Name="btnComplete" Height="26" Width="26" DockPanel.Dock="Right" HorizontalAlignment="Right" Click="btnComplete_Click" ToolTip="Complete Action" >
<Image Source="/SMS_Main;component/Resources/OK_24.png" Margin="2" />
</Button>
<Button Name="btnCancel" Height="26" Width="26" DockPanel.Dock="Right" HorizontalAlignment="Right" Click="btnCancel_Click" ToolTip="Remove Action">
<Image Source="/SMS_Main;component/Resources/Cancel_24.png" Margin="2" />
</Button>
<Button Name="btnRevert" Height="26" Width="26" DockPanel.Dock="Right" HorizontalAlignment="Right" Click="btnRevert_Click" IsEnabled="{Binding Path=CurrentlySaved}" ToolTip="Revert Change">
<Image Source="/SMS_Main;component/Resources/Undo_24.png" Margin="2" />
</Button>
<Button Name="btnEdit" Height="26" Width="26" DockPanel.Dock="Right" HorizontalAlignment="Right" Click="btnEdit_Click" ToolTip="Edit Action" >
<Image Margin="2" Source="/SMS_Main;component/Resources/Config_24.png" />
</Button>
<TextBlock Name="txbAssignedTo" Text="{Binding Path=AssignedUser}" VerticalAlignment="Center" DockPanel.Dock="Right" HorizontalAlignment="Left" Margin="95,0,10,0" />
</DockPanel>
</DockPanel>
</Grid>
</UserControl>
.
You can add an event trigger to the cancel button:
<Button Name="btnCancel" Height="26" Width="26" DockPanel.Dock="Right" HorizontalAlignment="Right" ToolTip="Remove Action" Content="Cancel">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="IsEnabled" Storyboard.TargetName="dtpCompleted">
<DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="False"/>
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>

Text box value is not updated in ViewModel when changing in the view in WPF

When I change the text box value, it is not updated in the view model.
This is my text box xaml in the view
<TextBox Height="23" HorizontalAlignment="Left" Margin="153,65,0,0" Name="textBox2" VerticalAlignment="Top" Width="120" Text="{Binding Path=InstallPath, Mode=TwoWay}"/>
Full xaml for the view,
<Window.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
</Window.Resources>
<Grid>
<Button Content="Configure Logger" Height="44" HorizontalAlignment="Left" Margin="402,125,0,0" Name="button1" VerticalAlignment="Top" Width="108" Click="button1_Click" />
<Button Content="Load DB" Height="43" HorizontalAlignment="Left" Margin="402,200,0,0" Name="button3" VerticalAlignment="Top" Width="108" Click="button3_Click" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="46,36,0,0" Name="textBlock1" Text="SQL Server" VerticalAlignment="Top" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="153,36,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" TextChanged="textBox1_TextChanged" />
<GroupBox Header="DB Names" HorizontalAlignment="Left" Margin="54,114,0,0" Name="groupBox1" VerticalAlignment="Top" >
</GroupBox>
<TextBlock Text="Test bootstrapper application." Margin="10" FontSize="18" HorizontalAlignment="Center" Foreground="Red" VerticalAlignment="Top" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="46,65,0,0" Name="textBlock2" Text="Installation Path" VerticalAlignment="Top" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="153,65,0,0" Name="textBox2" VerticalAlignment="Top" Width="120" Text="{Binding Path=InstallPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<Ellipse Height="100" Width="100" HorizontalAlignment="Center" VerticalAlignment="Center" StrokeThickness="6" Margin="278,129,216,112"
Visibility="{Binding Path=IsThinking, Converter={StaticResource BooleanToVisibilityConverter}}">
<Ellipse.Stroke>
<LinearGradientBrush>
<GradientStop Color="Red" Offset="0.0"/>
<GradientStop Color="White" Offset="0.9"/>
</LinearGradientBrush>
</Ellipse.Stroke>
<Ellipse.RenderTransform>
<RotateTransform x:Name="Rotator" CenterX="50" CenterY="50" Angle="0"/>
</Ellipse.RenderTransform>
<Ellipse.Triggers>
<EventTrigger RoutedEvent="Ellipse.Loaded">
<BeginStoryboard>
<Storyboard TargetName="Rotator" TargetProperty="Angle">
<DoubleAnimation By="360" Duration="0:0:2" RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Ellipse.Triggers>
</Ellipse>
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Right">
<Button Content="Install" Command="{Binding Path=InstallCommand}" Visibility="{Binding Path=InstallEnabled, Converter={StaticResource BooleanToVisibilityConverter}}" Margin="10" Height="20" Width="80"/>
<Button Content="Uninstall" Command="{Binding Path=UninstallCommand}" Visibility="{Binding Path=UninstallEnabled, Converter={StaticResource BooleanToVisibilityConverter}}" Margin="10" Height="20" Width="80"/>
<Button Content="Exit" Command="{Binding Path=ExitCommand}" Margin="10" Height="20" Width="80" />
</StackPanel>
</Grid>
ViewModel
private string installPath;
public string InstallPath
{
get { return installPath; }
set
{
installPath = value;
RaisePropertyChanged("InstallPath");
}
Method which consumes the text box value in WIX Bootstrapper
protected override void Run()
{
MainViewModel viewModel = new MainViewModel(this);
BootstrapperDispatcher = Dispatcher.CurrentDispatcher;
MainView view = new MainView();
view.DataContext = viewModel;
this.Engine.Log(LogLevel.Verbose, "My text input is: " + view.textBox2.Text);
viewModel.Bootstrapper.Engine.StringVariables["MyBurnVariable1"] = viewModel.InstallPath;
}
viewModel.InstallPath is empty even though I change the value in textbox, Do I miss something?
I am just following the below WIX Bootstrapper example explained in the below link,
http://bryanpjohnston.com/2012/09/28/custom-wix-managed-bootstrapper-application/
Your bindings and setups seems ok with the code you have provided.
You should note that the default UpdateSourceTrigger of the TextBox is LostFocus, so that your property is only updated when the TextBox lost focus.
You can change the UpdateSourceTrigger to PropertyChanged, so that every time Text is written in the TextBox your property gets updated.
You set up the UpdateSourceTrigger in the binding as follows
<TextBox Text="{Binding Path=InstallPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
You need to use UpdateSourceTrigger=PropertyChange in order to reflect your view change Back into ViewModel.
<TextBox Text="{Binding Path=InstallPath,Mode=TwoWay,UpdateSourceTrigger=PropertyChange}"/>

How to spread/stretch textual content over an area?

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>

Resources