Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 2.80 KB  |  hits: 27  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to change the WP7 List SelectedItem Background in Dynamic Data template?
  2. <ListBox Margin="0" Name="MyListBox" ItemContainerStyle="{StaticResource ListBoxItemStyle1}" />
  3.  
  4.  
  5. <Style x:Key="ListBoxItemStyle1" TargetType="ListBoxItem">
  6.   <Setter Property="Background" Value="Transparent"/>
  7.   <Setter Property="BorderThickness" Value="0"/>
  8.   <Setter Property="BorderBrush" Value="Transparent"/>
  9.   <Setter Property="Padding" Value="0"/>
  10.   <Setter Property="HorizontalContentAlignment" Value="Left"/>
  11.   <Setter Property="VerticalContentAlignment" Value="Top"/>
  12.   <Setter Property="Template">
  13.   <Setter.Value>
  14.     <ControlTemplate TargetType="ListBoxItem">
  15.       <Border x:Name="LayoutRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
  16.         <VisualStateManager.VisualStateGroups>
  17.           <VisualStateGroup x:Name="CommonStates">
  18.             <VisualState x:Name="Normal"/>
  19.             <VisualState x:Name="MouseOver"/>
  20.             <VisualState x:Name="Disabled">
  21.               <Storyboard>
  22.                 <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="LayoutRoot">
  23.                   <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TransparentBrush}"/>
  24.                 </ObjectAnimationUsingKeyFrames>
  25.                 <DoubleAnimation Duration="0" To=".5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ContentContainer"/>
  26.               </Storyboard>
  27.             </VisualState>
  28.           </VisualStateGroup>
  29.           <VisualStateGroup x:Name="SelectionStates">
  30.             <VisualState x:Name="Unselected"/>
  31. <!-- This is the bit you are specifically interested in -->
  32.               <VisualState x:Name="Selected">
  33.                 <Storyboard>
  34.                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
  35.                      <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneAccentBrush"/>
  36.                    </ObjectAnimationUsingKeyFrames>
  37.                 </Storyboard>
  38.               </VisualState>
  39. <!-- This is the end of the bit you are specifically interested in -->
  40.             </VisualStateGroup>
  41.           </VisualStateManager.VisualStateGroups>
  42.           <ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
  43.         </Border>
  44.       </ControlTemplate>
  45.     </Setter.Value>
  46.     </Setter>
  47.   </Style>