ListBoxItem style : ListBoxItem « UI Controls « Silverlight






ListBoxItem style

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>

   
    
    
  








Related examples in the same category

1.Customizing the Default ListBoxItem UICustomizing the Default ListBoxItem UI
2.Using a ListBoxItem as a ContentControlUsing a ListBoxItem as a ContentControl
3.Using an ItemsPresenterto display the Itemsof an ItemsControlUsing an ItemsPresenterto display the Itemsof an ItemsControl
4.Declaring the ItemsPanel to arrange the Items of an ItemsControlDeclaring the ItemsPanel to arrange the Items of an ItemsControl