Articles in this section
Category / Section

How to change the size of the sort icon in Xamarin DataGrid (SfDataGrid)?

4 mins read

SfDataGrid allows you to modify the size of the SortIcon header. This can be achieved by overriding OnInitializeDisplayView method in custom SfDataGrid.GridHeaderCellRenderer and changing the size of its parent element.

 

public partial class MainPage : ContentPage
{
  public MainPage()
  {
    InitializeComponent();
    dataGrid.CellRenderers.Remove("HeaderView");
    dataGrid.CellRenderers.Add("HeaderView", new HeaderCellRenderer());
  }
}
 
public class HeaderCellRenderer: GridHeaderCellRenderer
{
  public override void OnInitializeDisplayView(DataColumnBase dataColumn, ContentView view)
  {
    base.OnInitializeDisplayView(dataColumn, view);
    ((view as BorderView).Content as Grid).ColumnDefinitions[1].Width = new GridLength(20, GridUnitType.Absolute);
  }
}

 

SortIcon customization

 

View sample in GitHub

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied