我试图重新从Windows 8在WPF应用程序在Windows 7上运行的邮件UI这是我想达到的目标:如何设置WPF ListView Selected Item颜色?
特别是,我不知道如何改变选定项目的背景颜色,例如第一列中的收件箱项目和第二列中的Twitter邮件。我已经尝试了其他类似的Stackoverflow问题的几个解决方案,但似乎没有为我工作。例如
Selected item loses style when focus moved out in WPF ListBox
WPF ListView Inactive Selection Color
这里是我有我的列表视图代码:
<ListView Grid.Row="0" SelectedItem="{Binding Path=SelectedArea}" ItemsSource="{Binding Path=Areas}" Background="#DCE3E5" >
<ListView.Resources>
<!-- Template that is used upon selection of an Area -->
<ControlTemplate x:Key="SelectedTemplate" TargetType="ListViewItem">
<Border Background="#388095" Cursor="Hand" >
<TextBlock Text="{Binding Name}" Margin="5" />
</Border>
</ControlTemplate>
<Style TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<!-- Base Template that is replaced upon selection -->
<ControlTemplate TargetType="ListViewItem">
<Border Background="#DCE3E5" Cursor="Hand" >
<TextBlock Text="{Binding Name}" Margin="5" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="true" />
</MultiTrigger.Conditions>
<Setter Property="Template" Value="{StaticResource SelectedTemplate}" />
</MultiTrigger>
</Style.Triggers>
</Style>
</ListView.Resources>
</ListView>
如何更改所选项目的背景颜色?如何在焦点改变时保持颜色变化。
感谢@TrueEddie
ListViewItemOptionStyle。我的机器正在发挥作用,我无法测试您的解决方案。我将尽快恢复我的机器。 – Yasir 2013-02-12 19:36:30
这显示正确的选择。但是现在我们正在使用TextBlock而不是我正在使用的超链接,我不再能够提供我需要调用的Command。我如何提供命令和相关参数?当我用超链接替换你的Border元素时,它允许我在超链接之外单击时改变颜色,但不让我调用该命令。当我点击超链接时,它允许我使用命令,但颜色不会改变。 – Yasir 2013-02-13 20:25:52
我编辑了我上面的答案。 – TrueEddie 2013-02-13 21:05:57