我在ListView上使用(3.5版本的新版本) AlternationIndex触发器来应用如下的交替背景颜色:
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Style.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="White" />
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="#300761AE" />
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>这部分工作很好,ListView看起来就像我想要的那样。我唯一的问题是SelectedItem的背景颜色。对于我的列表,实际上不能选择项目,因为这在上下文中是没有意义的。我正在尝试寻找一种方法,使SelectedItem的背景颜色为nothing,这样父ListViewItem的颜色就会显现出来。透明不起作用,因为它本质上等同于白色,当我使用透明时,交替样式就消失了。它也不会让我将它设置为null。
我知道我需要更改SystemColors.HighlightBrushKey,但是我不知道如何设置绑定来找到父ListViewItem的背景颜色。这是一次尝试:
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListViewItem}}, Path=Background}" />这有可能做到吗?
发布于 2011-07-27 13:39:27
您是否尝试过将事件处理程序附加到SelectionChanged事件并将SelectedItem设置为null
private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var listview = sender as ListView;
if (listview != null)
listview.SelectedItem = null;
}发布于 2011-07-27 13:49:55
试一下这个
<Style TargetType="ListViewItem">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Green"/>
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="LightBlue"/>
</Style.Resources>
</Style>http://imduff.wordpress.com/2008/03/01/change-highlight-color-when-an-item-in-a-listview-is-selected/
https://stackoverflow.com/questions/6839753
复制相似问题