如何在我的行中保留文本,例如當DataGrid行被選中時爲白色,以及當它處於非活動選擇模式時(它被選中現在用戶點擊另一個控件即文本框)。當選擇單元格/行時更改單元格/行的文本顏色 - DataGrid WPF
我試着用這個(設置單元格樣式):
<DataGrid.CellStyle>
<StaticResource ResourceKey="DataGridCentering"/>
</DataGrid.CellStyle>
如果我在App.xaml中說:
<Style x:Key="DataGridCentering" TargetType="{x:Type DataGridCell}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
由於可以注意到,我試圖做到這一點的觸發器,即當單元格被選中顏色我的文本內的單元格與白色等, 但遺忘地這是行不通的
當我選擇單元格/行時DataGrid中的文本仍然是黑色的..
[設置選中行時WPF DataGrid行的文本顏色]的可能重複(http://stackoverflow.com/questions/4104646/setting-the-text-colour-of-a-wpf-datagrid- row-when-row-is-selected) – AlSki