Set SortComparer in Style / ResourceDictionary

I am trying to create a base style for multiple SfDataGrid Controls in my application.
Therefore i want to create a custom comparer like this https://help.syncfusion.com/wpf/datagrid/sorting - no problem so far.
But I can't add the custom comparer to my base style in a resource dictionary because the setter of the SortComparers property is not available.


Is there a way to add custom comparer to my base style of SfDataGrid in resource dictionary?

1 Reply 1 reply marked as answer

DM Dhanasekar Mohanraj Syncfusion Team September 8, 2020 03:19 PM UTC

Hi Sandmaann,

Thanks for contacting syncfusion support. 
Your requirement can be achieved by defining the sort comparer in CustomDataGrid,
please refer the below code sample.

Code example:
C#:
 
public class CutomDataGrid : SfDataGrid 
{ 
    public CutomDataGrid() 
    { 
        this.SortComparers.Add(new SortComparer() { Comparer = new CustomComparer(), PropertyName = "CustomerName" }); 
    } 
} 

XAML: 
<Window.Resources> 
    <Style TargetType="local:CutomDataGrid"> 
        <Setter Property="AllowFiltering" Value="True"/> 
        <Setter Property="AllowSorting" Value="True"/>                      
        <Setter Property="Foreground" Value="Blue"/> 
        <Setter Property="Background" Value="Cyan"/> 
    </Style> 
</Window.Resources> 

Please let us know if you require further assistance from us. 
Regards,
Dhanasekar Mohanraj 


Marked as answer
Loader.
Up arrow icon