【发布时间】:2013-10-11 21:33:30
【问题描述】:
一天中的美好时光,亲爱的 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 时添加背景阴影效果)?
【问题讨论】:
-
您的目标是什么版本的 .Net?
BitmapEffects 已被弃用,因为它们存在性能问题。你不应该使用它们。 -
我使用的是 .net 3.5。你会推荐我用什么来代替 BitmapEffect?
标签: wpf