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>

 

转载于:https://www.cnblogs.com/zany-hui/articles/3843836.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值