var group = (dataGrid.View.Groups[0] as Group);
this.dataGrid.ExpandGroup(group);
this.dataGrid.CollapseGroup(group);
public static class Commands { static Commands() { CommandManager.RegisterClassCommandBinding(typeof(SfDataGrid), new CommandBinding(ExpandGroup, OnExpandGroup, OnCanExpandCollapse)); CommandManager.RegisterClassCommandBinding(typeof(SfDataGrid), new CommandBinding(CollapseGroup, OnCollapseGroup, OnCanExpandCollapse)); } public static RoutedCommand ExpandGroup = new RoutedCommand("ExpandGroup", typeof(SfDataGrid)); public static RoutedCommand CollapseGroup = new RoutedCommand("CollapseGroup", typeof(SfDataGrid)); private static void OnExpandGroup(object sender, ExecutedRoutedEventArgs args) { var dataGrid = args.Source as SfDataGrid; var group = (dataGrid.View.Groups[0] as Group); dataGrid.ExpandGroup(group); } private static void OnCollapseGroup(object sender, ExecutedRoutedEventArgs args) { var dataGrid = args.Source as SfDataGrid; var group = (dataGrid.View.Groups[0] as Group); dataGrid.CollapseGroup(group); } private static void OnCanExpandCollapse(object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = true; } } |