我試圖重新從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