ListViewItem在选择时闪烁

时间:2013-10-11 21:33:31

标签: wpf

一天中的好时光,亲爱的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时添加背景阴影效果)?

1 个答案:

答案 0 :(得分:0)

天啊,那是凌晨3点,我在应用程序逻辑中做了非常愚蠢的错误。所以,问题解决了,并且遵循XAML的工作原理!