2012-12-05 50 views
1

我在我的數據網格行上實施了上下文菜單。當你右鍵點擊一行時,它會在打開上下文菜單之前簡要地突出顯示它。據我瞭解,這是因爲數據網格失去了重點。更改未聚焦的選定數據網格行的顏色

我試圖用SystemColors.ControlBrushKey更改未聚焦但尚未選中的顏色,但它沒有效果。這是不正確的?我發現了幾個ListBox相關解決方案,這是可以接受的解決方案。系統顏色以供參考

<Style x:Key="DefaultRowStyle" TargetType="{x:Type DataGridRow}"> 
    <Style.Resources> 
     <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Black" /> 
     <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Yellow" /> 
    </Style.Resources> 
</Style> 

全部列表:http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-64-SystemColors+Reference/6266.swatch_5F00_Amalgam.png

回答

2

你唯一的選擇是將風格XAML從here複製和更改顏色設置在裏面。 XAML中的註釋表明,除非您更改樣式,否則他們提供的XAML中的一些狀態無法區分。

<VisualState x:Name="Unfocused_Selected"> 
    <Storyboard> 
    <ColorAnimationUsingKeyFrames Storyboard.TargetName="DGR_Border" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)"> 
     <EasingColorKeyFrame KeyTime="0" Value="{StaticResource ControlMediumColor}" /> 
    </ColorAnimationUsingKeyFrames> 
    <ColorAnimationUsingKeyFrames Storyboard.TargetName="DGR_Border" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)"> 
     <EasingColorKeyFrame KeyTime="0" Value="{StaticResource ControlDarkColor}" /> 
    </ColorAnimationUsingKeyFrames> 
    </Storyboard> 
</VisualState> 

編輯:我鏈接了錯誤的頁面。這是Silverlight的風格(doh!)。我已經修復了指向WPF風格的鏈接。我也複製了WPF風格的適用區域。

+0

我抄襲了模板的'Setter'。當我把它粘貼到我的項目中時,它說'DataGridRow'不是作爲'System.Windows.Controls'命名空間的一部分存在,所有試圖在'localprimitives'命名空間上訪問的元素都是如此[ – Julien

+0

]我是看着銀色的風格。我已更新WPF。 –

+0

Ha。所以這個工作,但只是部分。只有在所有列結束後的行結束纔會突出顯示。事實上,它突出顯示了默認突出顯示的行的完全相反的部分 – Julien

相關問題