bool IsEnabled(RoutedCommand command) { if (command.CanExecute(null, null)) return true; else if (this.Child != null) return command.CanExecute(null, FocusManager.GetFocusedElement(FocusManager.GetFocusScope(this.Child))); else return false; }
void Run(RoutedCommand command) { if (command.CanExecute(null, null)) { command.Execute(null, null); } else if (this.Child != null) { command.Execute(null, FocusManager.GetFocusedElement(FocusManager.GetFocusScope(this.Child))); } }
public static void MapCommand(ICommand source, RoutedCommand target, UIElement element) { Contract.Requires(null != source, "source"); Contract.Requires(null != target, "target"); Contract.Requires(null != element, "element"); var binding = new CommandBinding(target, (sender, args) => { source.Execute(args.Parameter); }, (sender, args) => { args.CanExecute = source.CanExecute(args.Parameter); } ); element.CommandBindings.Add(binding); source.CanExecuteChanged += (sender, args) => { target.CanExecute(null, element); }; }
private bool EndEdit(RoutedCommand command, DataGridCell cellContainer, DataGridEditingUnit editingUnit, bool exitEditMode) { bool cellLeftEditingMode = true; bool rowLeftEditingMode = true; if (cellContainer != null) { if (command.CanExecute(editingUnit, cellContainer)) { command.Execute(editingUnit, cellContainer); } cellLeftEditingMode = !cellContainer.IsEditing; rowLeftEditingMode = !IsEditingRowItem && !IsAddingNewItem; } if (!exitEditMode) { if (editingUnit == DataGridEditingUnit.Cell) { if (cellContainer != null) { if (cellLeftEditingMode) { return BeginEdit(null); } } else { // A cell was not placed in edit mode return false; } } else { if (rowLeftEditingMode) { object rowItem = cellContainer.RowDataItem; if (rowItem != null) { EditRowItem(rowItem); return IsEditingRowItem; } } // A row item was not placed in edit mode return false; } } return cellLeftEditingMode && ((editingUnit == DataGridEditingUnit.Cell) || rowLeftEditingMode); }
bool CanExecute(RoutedCommand command) { TextArea area = this.TextArea; if (area == null) { return false; } else { return command.CanExecute(null, area); } }