<DataTemplate.Triggers> <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType=DataGridRow}}" Value="True"> <Setter TargetName="TextBoxStackPanel" Property="Background" Value="White"/> </DataTrigger> <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType=DataGridCell}}" Value="True"> <Setter TargetName="TextBoxStackPanel" Property="Background" Value="White"/> </DataTrigger> </DataTemplate.Triggers>
以上分别为行选中和单元格选中时触发
TextBoxStackPanel为 DataTemplate 下的子元素StackPanel的Name标签:DataGrid,参考,cell,背景色,选中,wpf From: https://www.cnblogs.com/wuguoqiang/p/16985323.html