Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight 更改列表框中selecteditem的样式_Silverlight_Listbox_Visualstatemanager_Selecteditemtemplate - Fatal编程技术网

Silverlight 更改列表框中selecteditem的样式

Silverlight 更改列表框中selecteditem的样式,silverlight,listbox,visualstatemanager,selecteditemtemplate,Silverlight,Listbox,Visualstatemanager,Selecteditemtemplate,我有一个滚动查看器: <ScrollViewer Width="160" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Hidden" Height="324" Canvas.Top="0" BorderThickness="0" Padding="0"> <ListB

我有一个滚动查看器:

<ScrollViewer Width="160" 
              VerticalScrollBarVisibility="Auto" 
              HorizontalScrollBarVisibility="Hidden" 
              Height="324" Canvas.Top="0" 
              BorderThickness="0" Padding="0">
   <ListBox 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>
</ScrollViewer>

如何实现这些功能:

  • 更改选定项目(图像)的不透明度
  • 更改选定项目(图像)的默认边框样式

  • 更改
    列表框中的
    ItemContainerStyle
    。小样本来自:

    
    ...
    ...
    ...
    
    您还可以在
    选中的
    VisualState中使用边框制作动画。

    谢谢, 它现在正在工作。 这是我更新后的风格:

    <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>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ImageBorder" Storyboard.TargetProperty="Visibility" Duration="0">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                            <DoubleAnimation Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="Opacity" Duration="0" To="1"/>
                                        </Storyboard>
    
                                    </vsm:VisualState>
                                </vsm:VisualStateGroup>
                            </vsm:VisualStateManager.VisualStateGroups>
                            <ContentPresenter
                                  x:Name="contentPresenter"
                                  Content="{TemplateBinding Content}"
                                  ContentTemplate="{TemplateBinding ContentTemplate}"
                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                  Opacity="0.2"
                                  Margin="{TemplateBinding Padding}" />
                            <Border BorderBrush="Black" BorderThickness="5" x:Name="ImageBorder" Visibility="Collapsed"/>
                        </Grid>
    
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    
    
    看得见的
    
    这是列表框:

     <ScrollViewer Width="160" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Hidden" Height="324" Canvas.Top="0" BorderThickness="0" Padding="0">
                                <ListBox ItemContainerStyle="{StaticResource ItemContainerStyle}" x:Name="ListBox_AcceptedPhotos" 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" MouseLeftButtonUp="Image_MouseLeftButtonUp" />
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <StackPanel Orientation="Vertical"  VerticalAlignment="Top"  HorizontalAlignment="Center"/>
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>
                                </ListBox>
                            </ScrollViewer>
    
    
    
    xmlns:vsm=“clr命名空间:System.Windows;assembly=System.Windows”