2014-02-17 54 views
1

設置後臺對DataGridCheckBoxColumn正常工作,但對於DataGridTextColumn不適用。我將它設置爲資源中的單元格:如何在WPF中IsEditing = True時更改DataGridCell的背景

<Style TargetType="{x:Type DataGridCell}"> 
    <Style.Triggers> 
     <Trigger Property="IsSelected" Value="True"> 
      <Setter Property="Background" Value="#ffff00" /> 
     </Trigger> 

     <Trigger Property="IsEditing" Value="True"> 
      <Setter Property="BorderThickness" Value="1" /> 
      <Setter Property="BorderBrush" Value="#00ff00" /> 
      <Setter Property="Background" Value="#00ff00" /> 
     </Trigger> 
    </Style.Triggers> 
</Style> 

有沒有針對此問題的解決方案?在<Window.Resources>

<SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}" Color="Transparent" /> 
在你的資源

,例如:

+0

這觸發不工作? – franssu

+0

'IsEditing'不能在'DataGridTextColumn'中使用,因爲它在編輯模式下有自己的背景風格,我想 –

回答

2

您應該添加magic字符串。

在這種情況下,當IsEditing="True"顏色由默認(White),其從所述拍攝SystemColors分配。但是,您需要明確設置主面板或Window的顏色。

或者設置該字符串<DataGrid.Resources>Background="White"

<DataGrid Background="White" ...> 
    <DataGrid.Resources> 
     <SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}" Color="Transparent" /> 
    </DataGrid.Resources> 
     ... 
</DataGrid> 
相關問題