Silverlight Listbox selecteditem style
<Style x:Key="ItemContainerStyle" TargetType="ListBoxItem"> ... <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBoxItem"> <Grid Background="{TemplateBinding Background}"> <vsm:VisualStateManager.VisualStateGroups> ... <vsm:VisualStateGroup x:Name="SelectionStates"> <vsm:VisualState x:Name="Unselected" /> <vsm:VisualState x:Name="Selected"> <Storyboard> <DoubleAnimation Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="Opacity" Duration="0" To=".75"/> </Storyboard> </vsm:VisualState> </vsm:VisualStateGroup> ... </vsm:VisualStateManager.VisualStateGroups> <ContentPresenter x:Name="contentPresenter" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> <ListBox ItemContainerStyle="{StaticResource ItemContainerStyle}" x:Name="Snapshots" SelectionChanged="Snapshots_SelectionChanged" Padding="0" Background="#FFF0F0F0" BorderBrush="{x:Null}" VerticalAlignment="Top" SelectionMode="Single"> <ItemsControl.ItemTemplate> <DataTemplate> <Image Source="{Binding imageSource}" Margin="5" Stretch="UniformToFill" Width="120" Opacity="0.2"/> </DataTemplate> </ItemsControl.ItemTemplate> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Vertical" VerticalAlignment="Top" HorizontalAlignment="Center"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ListBox>
<DataTemplate> <Grid> <ContentPresenter Grid.Column="0" Content="{Binding Property1}" Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ListBoxItem}, Path=IsSelected, Converter={StaticResource InvertedBoolToVisibilityConverter}}"> <ContentPresenter.ContentTemplate> <DataTemplate> <TextBlock Text="{Binding}" Foreground="Red" FontSize="20" /> </DataTemplate> </ContentPresenter.ContentTemplate> </ContentPresenter> <ContentPresenter Grid.Column="1" Content="{Binding Property1}" Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ListBoxItem}, Path=IsSelected, Converter={StaticResource BoolToVisibilityConverter}}"> <ContentPresenter.ContentTemplate> <DataTemplate> <TextBox Text="{Binding}" Foreground="Purple" FontSize="20" /> </DataTemplate> </ContentPresenter.ContentTemplate> </ContentPresenter> </Grid> </DataTemplate>