syncfusion:SfDataGrid.HeaderContextMenu>
<MenuFlyout>
<MenuFlyoutItem Text="Sort Ascending" Command="{Binding Path=DataContext.SortAscendingCommand}" CommandParameter="{Binding}" />
</MenuFlyout>
</syncfusion:SfDataGrid.HeaderContextMenu>
private DelegateCommand _sortAscendingCommand;
public DelegateCommand SortAscendingCommand
{
get
{
if (_sortAscendingCommand == null)
_sortAscendingCommand = new DelegateCommand(CanSortAscending, SortAscending);
return _sortAscendingCommand;
}
set { _sortAscendingCommand = value; }
}
private void SortAscending(object param)
{
if (param is GridColumnContextMenuInfo)
{
var grid = (param as GridContextMenuInfo).DataGrid;
var column = (param as GridColumnContextMenuInfo).Column;
grid.SortColumnDescriptions.Clear();
grid.SortColumnDescriptions.Add(new SortColumnDescription() { ColumnName = column.MappingName, SortDirection = ListSortDirection.Ascending });
}
} |