Is there a way to sort a WPF DataGrid programmaticaly ( for example, like if i clicked on my first column).
Is there a way to simuate this click ? Or a best way ?
PerformSort method of the DataGrid is what actually executed on a column's header click. However this method is internal. So if you really want to simulate the click you need to use reflection:
public static void SortColumn(DataGrid dataGrid, int columnIndex)
{
var performSortMethod = typeof(DataGrid)
.GetMethod("PerformSort",
BindingFlags.Instance | BindingFlags.NonPublic);
performSortMethod?.Invoke(dataGrid, new[] { dataGrid.Columns[columnIndex] });
}