2013-10-11 100 views
1

一天中的好時光,親愛的StackOverflow用戶!所以,我有以下XAML代碼的ListView:ListViewItem閃爍選擇

<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)?

+0

您定位的是什麼版本的.Net? 'BitmapEffect'已被棄用,因爲它們有性能問題。你不應該使用它們。 –

+0

我正在使用.net 3.5。你會推薦我用什麼來代替BitmapEffect? – asn007

回答

0

哦,上帝,那是凌晨3點,我在應用程序邏輯中做了非常愚蠢的錯誤。所以,這個問題就解決了,下面的XAML工作!