No RowStyleSelector selected

I find it hard to get a RowStyleSelector to work with DataGrid WPF.

In my resources I have

<loc:DetailsRowStyleSelector x:Key="detailsRowStyleSelector" AddRowStyle="{StaticResource newItemRowStyle}" StandardRowStyle="{StaticResource RowStyle}"/> 

Then my datagrid uses it like this:

 <DataGrid ... EnableRowVirtualization="false" VirtualizingStackPanel.VirtualizationMode="Standard" RowStyleSelector="{StaticResource detailsRowStyleSelector}" 

The constructor for the selector is called, but the SelectStyle method is not, and my lines look the same. This seems like very little documentation, 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 
+4
source share
1 answer

Most likely, you have either a RowStyle or ItemContainerStyle installed on a DataGrid , either locally or through an inherited style.

RowStyleSelector overrides ItemContainerStyleSelector , which includes the following statement in the documentation:

Note that this property is ignored if the ItemContainerStyle property is set .

+4
source

Source: https://habr.com/ru/post/1400444/


All Articles