Mega Code Archive

 
Categories / Silverlight / UI Controls
 

ListBoxItem style

<UserControl x:Class='SilverlightApplication3.MainPage'     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'      d:DesignWidth='640'      d:DesignHeight='480'     xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows">   <UserControl.Resources>     <Style x:Key="ListBoxItemStyle1" TargetType="ListBoxItem">       <Setter Property="Padding" Value="0"/>       <Setter Property="HorizontalContentAlignment" Value="Left"/>       <Setter Property="VerticalContentAlignment" Value="Top"/>       <Setter Property="BorderThickness" Value="0"/>       <Setter Property="TabNavigation" Value="Local"/>       <Setter Property="Template">         <Setter.Value>           <ControlTemplate TargetType="ListBoxItem">             <Grid Background="{TemplateBinding Background}">               <vsm:VisualStateManager.VisualStateGroups>                 <vsm:VisualStateGroup x:Name="CommonStates">                   <vsm:VisualState x:Name="Normal"/>                   <vsm:VisualState x:Name="MouseOver">                     <Storyboard>                       <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="fillColor" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">                         <SplineColorKeyFrame KeyTime="00:00:00.5" Value="Red"/>                       </ColorAnimationUsingKeyFrames>                     </Storyboard>                   </vsm:VisualState>                 </vsm:VisualStateGroup>                 <vsm:VisualStateGroup x:Name="SelectionStates">                   <vsm:VisualState x:Name="Unselected"/>                   <vsm:VisualState x:Name="Selected">                     <Storyboard>                       <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="fillColor" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">                         <SplineColorKeyFrame KeyTime="00:00:00.9" Value="Yellow"/>                       </ColorAnimationUsingKeyFrames>                     </Storyboard>                   </vsm:VisualState>                 </vsm:VisualStateGroup>               </vsm:VisualStateManager.VisualStateGroups>               <Rectangle x:Name="fillColor" IsHitTestVisible="False" Opacity="0.6" RadiusX="0.8" RadiusY="1" Fill="#800000FF"/>               <ContentPresenter HorizontalAlignment="Left" Margin="{TemplateBinding Padding}" x:Name="contentPresenter" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>             </Grid>           </ControlTemplate>         </Setter.Value>       </Setter>     </Style>   </UserControl.Resources>     <Grid x:Name="LayoutRoot" Background="Transparent">         <StackPanel Background="Transparent">     <ListBox x:Name="lbActivities" Background="#800000FF" >             <ListBoxItem x:Name="Activity1" Content="Cycling" Style="{StaticResource ListBoxItemStyle1}" />             <ListBoxItem x:Name="Activity2" Content="Hiking" Style="{StaticResource ListBoxItemStyle1}"  />             <ListBoxItem x:Name="Activity3" Content="Caving" Style="{StaticResource ListBoxItemStyle1}"  />     </ListBox>     </StackPanel>     </Grid> </UserControl>