In WPF, changing the color of the selected row is very simple, that is, using a trigger: for example, the DataGrid is used as an example: DataGrid. rowstyle style targettype = maid setterproperty = background value = white/style. triggers triggerproperty = ismouseover value = true setterproperty = background value = lightgray // trigger triggerprope
In WPF, changing the color of the selected row is very simple, that is, using a trigger: for example, using a DataGrid:
<DataGrid. rowstyle>
<Style targettype = "datagridrow">
<Setter property = "background" value = "white"/>
<Style. triggers>
<Trigger property = "ismouseover" value = "true">
<Setter property = "background" value = "lightgray"/>
</Trigger>
<Trigger property = "isselected" value = "true">
<Setter property = "background" value = "lightgray"/>
<Setter property = "foreground" value = "red"/>
</Trigger>
</Style. triggers>
</Style>
</DataGrid. rowstyle>
However, I tell you that if you do not set cellstyle, you will find that the above Code "looks like" does not work and is useless. This is the same for similar controls such as listview.
In fact, the above Code already works. Isselected is indeed triggered. Where is the problem?
The answer is correct on cellstyle. The background of rowstyle is changed, but cellstyle is not changed. You cannot see it.
That is to say, rowstyle is very embarrassing, because cellstyle is on it. So it will be overwritten. The reason is that black people, white people, and black clothes look black.
The change method is as follows:
Add cellstyle:
<DataGrid. cellstyle>
<Style targettype = "datagridcell">
<Style. triggers>
<Trigger property = "isselected" value = "true">
<Setter property = "background" value = "red"> </setter>
</Trigger>
</Style. triggers>
</Style>
</DataGrid. cellstyle>