1

一天中的美好时光,亲爱的 StackOverflow 用户!因此,我为 ListView 提供了以下 XAML 代码:

<ListView Name="texturepacks_list_wpf"
          Background="Transparent"
          HorizontalAlignment="Left"
          Height="150"
          Margin="225,171,0,0"
          VerticalAlignment="Top"
          Width="320"
          BorderThickness="0">
  <ListView.Resources>
    <ControlTemplate x:Key="SelectedTemplate"
                     TargetType="ListViewItem">
      <Grid Margin="0, 2, 0, 2">
        <StackPanel Orientation="Horizontal"
                    Height="30"
                    Width="305"
                    Background="{TemplateBinding Background}">
          <StackPanel.BitmapEffect>
            <!--<DropShadowEffect Color="#7c3c9a" Direction="320" Opacity="1" ShadowDepth="0"></DropShadowEffect>-->
            <OuterGlowBitmapEffect GlowColor="#7c3c9a"
                                   GlowSize="5"
                                   Noise="0" />
          </StackPanel.BitmapEffect>
          <Grid Width="5"></Grid>
          <Image Source="{StaticResource ResourceKey=texturepack_icon}"
                 Height="24"></Image>
          <Grid Width="20"></Grid>
          <Label Content="{Binding TexturepackName}"
                 Style="{StaticResource ResourceKey=PTSansBold}"
                 Foreground="#FFF"
                 FontSize="20px"
                 VerticalContentAlignment="Center"></Label>
        </StackPanel>
      </Grid>
    </ControlTemplate>
  </ListView.Resources>
  <ListView.BorderBrush>
    <SolidColorBrush Color="#000"
                     Opacity="0"></SolidColorBrush>
  </ListView.BorderBrush>
  <ListView.ItemContainerStyle>
    <Style TargetType="ListViewItem">
      <Setter Property="Background">
        <Setter.Value>
          <SolidColorBrush Color="#261635"
                           Opacity="1"></SolidColorBrush>
        </Setter.Value>
      </Setter>
      <Setter Property="Padding"
              Value="5" />
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="ListViewItem">
            <Grid Margin="0, 2, 0, 2">
              <StackPanel Orientation="Horizontal"
                          Height="30"
                          Width="305"
                          Background="{TemplateBinding Background}">
                <Grid Width="5"></Grid>
                <Image Source="{StaticResource ResourceKey=texturepack_icon}"
                       Height="24"></Image>
                <Grid Width="20"></Grid>
                <Label Content="{Binding TexturepackName}"
                       Style="{StaticResource ResourceKey=PTSansBold}"
                       Foreground="#FFF"
                       FontSize="20px"
                       VerticalContentAlignment="Center"></Label>
              </StackPanel>
            </Grid>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
      <Style.Triggers>
        <MultiTrigger>
          <MultiTrigger.Conditions>
            <Condition Property="IsSelected"
                       Value="true" />
            <Condition Property="Selector.IsSelectionActive"
                       Value="true" />
          </MultiTrigger.Conditions>
          <Setter Property="Template"
                  Value="{DynamicResource SelectedTemplate}" />
        </MultiTrigger>
      </Style.Triggers>
    </Style>
  </ListView.ItemContainerStyle>
</ListView>

当我单击 ListViewItem 时,它应该为其自身添加背景阴影效果。但是,它会暂时添加此效果,然后将其关闭(切换到默认样式)。我该如何做我所描述的(在 ListViewItem 的选择上添加背景阴影效果)?

4

1 回答 1

0

哦,天哪,那是凌晨 3 点,我在应用程序逻辑中犯了非常愚蠢的错误。所以,问题解决了,遵循 XAML 就可以了!

于 2013-10-12T07:08:43.590 回答