<UserControl x:Class="Recipe5_3.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="700" Height="800"
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows">
<UserControl.Resources>
<DataTemplate x:Key="dtProductInfo">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" VerticalAlignment="Center"
HorizontalAlignment="Left" Text="{Binding Name}"
Margin="3,3,3,3"/>
<StackPanel HorizontalAlignment="Left" Grid.Row="1"
Orientation="Horizontal" Margin="3,3,3,3">
<TextBlock Text="$" Margin="0,0,2,0" />
<TextBlock Grid.Row="1" Text="{Binding ListPrice}"/>
</StackPanel>
<StackPanel HorizontalAlignment="Left" Grid.Row="2"
Orientation="Horizontal" Margin="3,3,3,3">
<Ellipse Height="15" Width="15"
Fill="{Binding InventoryLevelBrush}" Margin="0,0,2,0" />
<TextBlock Text="{Binding InventoryLevelMessage}" />
</StackPanel>
</Grid>
</DataTemplate>
<!-- custom ListBoxItem control template -->
<ControlTemplate x:Key="ctCustomListBoxItem" TargetType="ListBoxItem">
<Grid Background="{TemplateBinding Background}"
Margin="{TemplateBinding Margin}">
<Grid.RowDefinitions>
<RowDefinition Height="0.225*" MinHeight="20"/>
<RowDefinition Height="0.775*"/>
</Grid.RowDefinitions>
<vsm:VisualStateManager.VisualStateGroups>
<vsm:VisualStateGroup x:Name="CommonStates">
<vsm:VisualStateGroup.Transitions>
<vsm:VisualTransition
GeneratedDuration="00:00:00.0500000" To="MouseOver"/>
<vsm:VisualTransition
GeneratedDuration="00:00:00.0500000" From="MouseOver"/>
</vsm:VisualStateGroup.Transitions>
<vsm:VisualState x:Name="Normal">
<Storyboard/>
</vsm:VisualState>
<vsm:VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimationUsingKeyFrames
BeginTime="00:00:00"
Duration="00:00:00.0010000"
Storyboard.TargetName="BottomBorder"
Storyboard.TargetProperty=
"(Border.Background).(SolidColorBrush.Color)">
<SplineColorKeyFrame KeyTime="00:00:00" Value="#FF68A3DE"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</vsm:VisualState>
</vsm:VisualStateGroup>
<vsm:VisualStateGroup x:Name="SelectionStates">
<vsm:VisualState x:Name="Unselected">
<Storyboard/>
</vsm:VisualState>
<vsm:VisualState x:Name="Selected">
<Storyboard>
<ColorAnimationUsingKeyFrames
BeginTime="00:00:00"
Duration="00:00:00.0010000"
Storyboard.TargetName="TopBorder"
Storyboard.TargetProperty=
"(Border.Background).(SolidColorBrush.Color)">
<SplineColorKeyFrame KeyTime="00:00:00" Value="#FFFF2D00"/>
</ColorAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames
BeginTime="00:00:00"
Duration="00:00:00.0010000"
Storyboard.TargetName="SelectionIndicator"
Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="00:00:00">
<DiscreteObjectKeyFrame.Value>
<vsm:Visibility>Visible</vsm:Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</vsm:VisualState>
<vsm:VisualState x:Name="SelectedUnfocused">
<Storyboard>
<ColorAnimationUsingKeyFrames
BeginTime="00:00:00"
Duration="00:00:00.0010000"
Storyboard.TargetName="TopBorder"
Storyboard.TargetProperty=
"(Border.Background).(SolidColorBrush.Color)">
<SplineColorKeyFrame KeyTime="00:00:00" Value="#FFFF2D00"/>
</ColorAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames
BeginTime="00:00:00"
Duration="00:00:00.0010000"
Storyboard.TargetName="SelectionIndicator"
Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="00:00:00">
<DiscreteObjectKeyFrame.Value>
<vsm:Visibility>Visible</vsm:Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</vsm:VisualState>
</vsm:VisualStateGroup>
<vsm:VisualStateGroup x:Name="FocusStates">
<vsm:VisualState x:Name="Unfocused">
<Storyboard/>
</vsm:VisualState>
<vsm:VisualState x:Name="Focused">
<Storyboard>
<ObjectAnimationUsingKeyFrames
BeginTime="00:00:00"
Duration="00:00:00.0010000"
Storyboard.TargetName="FocusRect"
Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="00:00:00">
<DiscreteObjectKeyFrame.Value>
<vsm:Visibility>Visible</vsm:Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</vsm:VisualState>
</vsm:VisualStateGroup>
</vsm:VisualStateManager.VisualStateGroups>
<Border HorizontalAlignment="Stretch"
Margin="0,0,0,0"
VerticalAlignment="Stretch"
CornerRadius="5,5,0,0"
BorderBrush="#FF000000"
BorderThickness="2,2,2,0"
Background="#00000000"
x:Name="TopBorder">
<Grid x:Name="SelectionIndicator" Visibility="Collapsed"
Width="18" Height="18"
HorizontalAlignment="Left"
VerticalAlignment="Center" Margin="2,2,2,2">
<Path x:Name="Path" Stretch="Fill"
StrokeThickness="1.99975" StrokeLineJoin="Round"
Stroke="#FF000000" Fill="#FF27BC0F"
Data="F1 M 0.999876,18.0503C 2.60366,
16.4731 4.23013,14.9006 5.86216,13.3491L 12.6694,
18.7519C 14.239,10.2011 20.9487,3.27808 29.8744,
0.999878L 31.4453,2.68387C 23.1443,
9.95105 17.8681,19.7496 16.5592,
30.3293L 16.5592,30.2592L 0.999876,18.0503 Z "/>
</Grid>
</Border>
<Border Margin="0,0,0,0" CornerRadius="0,0,5,5"
BorderBrush="#FF000000" BorderThickness="2,2,2,2"
Grid.Row="1" Padding="3,3,3,3" x:Name="BottomBorder"
Background="#00000000">
<Grid>
<ContentPresenter HorizontalAlignment="Left"
Margin="3,3,3,3"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"/>
<Rectangle HorizontalAlignment="Stretch" Margin="0,0,0,0" Width="Auto"
Stroke="#FF000000"
StrokeDashArray="0.75 0.15 0.25 0.5 0.25"
x:Name="FocusRect" Visibility="Collapsed"/>
</Grid>
</Border>
</Grid>
</ControlTemplate>
<!-- style using the custom ListBoxItem control template -->
<Style x:Key="styleCustomListBoxItem" TargetType="ListBoxItem">
<Setter Property="Template"
Value="{StaticResource ctCustomListBoxItem}"/>
<Setter Property="Margin" Value="3,5,3,5" />
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White" Height="Auto" Margin="20,20">
<StackPanel Orientation="Horizontal" VerticalAlignment="Stretch"
HorizontalAlignment="Stretch">
<ListBox x:Name="lbxStandard" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" Margin="0,0,25,0"
ItemTemplate="{StaticResource dtProductInfo}" />
<!-- applying a custom ListBoxItemTemplate using the ItemContainerStyle -->
<ListBox x:Name="lbxCustom"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ItemTemplate="{StaticResource dtProductInfo}"
ItemContainerStyle="{StaticResource styleCustomListBoxItem}"/>
</StackPanel>
</Grid>
</UserControl>
|