I'm having difficulty getting a RowStyleSelector to work with a WPF DataGrid.
In my resources, I have
<loc:DetailsRowStyleSelector x:Key="detailsRowStyleSelector" AddRowStyle="{StaticResource newItemRowStyle}" StandardRowStyle="{StaticResource RowStyle}"/>
Then my datagrid uses this like so:
<DataGrid ...
EnableRowVirtualization="false"
VirtualizingStackPanel.VirtualizationMode="Standard"
RowStyleSelector="{StaticResource detailsRowStyleSelector}"
The constructor for the selector is called, but the SelectStyle method is not, and my rows all look the same. There seems to be very little documentation on this, but this is what my selector looks like:
public class DetailsRowStyleSelector : StyleSelector {
public Style AddRowStyle { get; set; }
public Style StandardRowStyle { get; set; }
public DetailsRowStyleSelector() {
Console.WriteLine(""); // this is called
}
public override Style SelectStyle(object item, DependencyObject container) {
// this is not called
The most likely cause is that you have either the RowStyle
or ItemContainerStyle
set on the DataGrid
, either locally or through an inherited style.
The RowStyleSelector
overrides the ItemContainerStyleSelector
, which includes the following statement in the documentation:
Note that this property is ignored if the ItemContainerStyle property is set.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With