private void CanExecuteChanged(object sender, EventArgs e) { if (Command != null) { RoutedCommand rc = Command as RoutedCommand; IsEnabled = rc?.CanExecute(CommandParameter, CommandTarget) ?? Command.CanExecute(CommandParameter); } }
private void CanExecuteChanged() { if (Command != null) { RoutedCommand command = Command as RoutedCommand; // If a RoutedCommand. if (command != null) { IsEnabled = command.CanExecute(CommandParameter, CommandTarget) ? true : false; } // If a not RoutedCommand. else { IsEnabled = Command.CanExecute(CommandParameter) ? true : false; } } }
internal static bool CanExecuteCommand(ICommand command, object parameter, IInputElement target) { if (command == null) { return(false); } RoutedCommand command2 = command as RoutedCommand; if (command2 != null) { return(command2.CanExecute(parameter, target)); } else { return(command.CanExecute(parameter)); } }
public static void ExecuteCommand(ICommand command, IInputElement element, object parameter) { RoutedCommand routedCommand = command as RoutedCommand; if (routedCommand != null) { if (routedCommand.CanExecute(parameter, element)) { routedCommand.Execute(parameter, element); } } else { if (command != null && command.CanExecute(parameter)) { command.Execute(parameter); } } }
internal static bool Execute(object sender, System.Windows.Input.ICommand command, object commandParameter) { if (command != null) { RoutedCommand routedCommand = command as RoutedCommand; IInputElement inputElement = sender as IInputElement; if (routedCommand != null && routedCommand.CanExecute(commandParameter, inputElement)) { routedCommand.Execute(commandParameter, inputElement); return(true); } else if (command.CanExecute(commandParameter)) { command.Execute(commandParameter); return(true); } } return(false); }
private static void uiElement_MouseDownInitial(object sender, MouseButtonEventArgs e) { UIElement uiElement = sender as UIElement; ICommand command = (ICommand)uiElement.GetValue(ClickBehavior.MouseClickCommandProperty); bool flag = false; if (command != null) { RoutedCommand routedCommand = command as RoutedCommand; object parameter = uiElement.GetValue(ClickBehavior.MouseEventParameterProperty) ?? (object)uiElement; flag = routedCommand == null?command.CanExecute(parameter) : routedCommand.CanExecute(parameter, (IInputElement)uiElement); } if (!flag) { return; } uiElement.MouseUp += new MouseButtonEventHandler(ClickBehavior.uiElement_MouseUp); e.MouseDevice.Capture((IInputElement)uiElement); e.Handled = true; }
/// <summary> /// This processes a given keystroke /// </summary> /// <param name="key">Key</param> /// <param name="modifiers">Modifier</param> /// <returns></returns> private bool HandleKeystroke(Key key, ModifierKeys modifiers) { foreach (var inputBinding in InputBindings) { KeyBinding keyBinding = inputBinding as KeyBinding; if (keyBinding == null) { continue; } if (keyBinding.Key == key && keyBinding.Modifiers == modifiers) { // Invoke the command ICommand command = keyBinding.Command; if (command != null) { var commandTarget = keyBinding.CommandTarget ?? this; // Normal (MVVM) command if (commandTarget == null || !typeof(RoutedCommand).IsAssignableFrom(command.GetType())) { if (command.CanExecute(keyBinding.CommandParameter)) { command.Execute(keyBinding.CommandParameter); } } // Target a specific UI element via RoutedCommand else { RoutedCommand rc = (RoutedCommand)command; if (rc.CanExecute(keyBinding.CommandParameter, commandTarget)) { rc.Execute(keyBinding.CommandParameter, commandTarget); } } return(true); } } } return(false); }
private void UpdateCanExecute() { if (Command != null) { RoutedCommand comRouted = Command as RoutedCommand; if (comRouted != null) { // Is RoutedCommand IsEnabled = comRouted.CanExecute(CommandParameter, CommandTarget); } else { // Is NOT RoutedCommand IsEnabled = Command.CanExecute(CommandParameter); } if (Target != null && SyncOwnerIsEnabled) { Target.IsEnabled = IsEnabled; } } }
private void _UpdateCanExecute() { if (this.Command != null) { object commandParameter = this.CommandParameter; IInputElement commandTarget = this.CommandTarget; RoutedCommand command = this.Command as RoutedCommand; if (command != null) { this._CanExecute = command.CanExecute(commandParameter, commandTarget); } else { this._CanExecute = this.Command.CanExecute(commandParameter); } } else { this._CanExecute = true; } }
// Custom command routing: // if the command isn't handled on the current focus, try to execute it on the focus inside the active workbench window void OnCanExecuteRoutedCommand(object sender, CanExecuteRoutedEventArgs e) { workbench.VerifyAccess(); RoutedCommand routedCommand = e.Command as RoutedCommand; AvalonWorkbenchWindow workbenchWindow = ActiveWorkbenchWindow as AvalonWorkbenchWindow; if (!e.Handled && routedCommand != null && workbenchWindow != null && !isInNestedCanExecute) { IInputElement target = workbenchWindow.GetCommandTarget(); if (target != null && target != e.OriginalSource) { isInNestedCanExecute = true; try { e.CanExecute = routedCommand.CanExecute(e.Parameter, target); } finally { isInNestedCanExecute = false; } e.Handled = true; } } }
/// <summary> /// Execute command /// </summary> protected void ExecuteCommand() { ICommand command = Command; if (command != null) { object commandParameter = CommandParameter; RoutedCommand routedCommand = command as RoutedCommand; if (routedCommand != null) { if (routedCommand.CanExecute(commandParameter, CommandTarget)) { routedCommand.Execute(commandParameter, CommandTarget); } } else if (command.CanExecute(commandParameter)) { command.Execute(commandParameter); } } }
private void UpdateCanExecute() { if (this.Command != null) { RoutedCommand comRouted = this.Command as RoutedCommand; if (comRouted != null) { //Is RoutedCommand this.IsEnabled = comRouted.CanExecute(this.CommandParameter, this.CommandTarget); } else { //Is NOT RoutedCommand this.IsEnabled = this.Command.CanExecute(this.CommandParameter); } if (this.Target != null && this.SyncOwnerIsEnabled) { this.Target.IsEnabled = IsEnabled; } } }
private void ExecuteCommand(EventArgs e) { ICommand command = this.Command; if (command != null) { object commandParameter = this.CommandParameter; if (commandParameter == null && this.PassEventArgsToCommand) { commandParameter = e; } IInputElement commandTarget = this.CommandTarget ?? this.visual as IInputElement; RoutedCommand routedCommand = command as RoutedCommand; if (routedCommand != null) { if (routedCommand.CanExecute(commandParameter, commandTarget)) { routedCommand.Execute(commandParameter, commandTarget); } } else { RoutedEventCommand eventCommand = command as RoutedEventCommand; if (eventCommand != null) { if (eventCommand.CanExecute(commandParameter)) { eventCommand.Execute(commandParameter, commandTarget); } } else if (command.CanExecute(commandParameter)) { command.Execute(commandParameter); } } } }
// Token: 0x0600787F RID: 30847 RVA: 0x002251B8 File Offset: 0x002233B8 internal static bool CanExecuteCommandSource(ICommandSource commandSource) { ICommand command = commandSource.Command; if (command == null) { return(false); } object commandParameter = commandSource.CommandParameter; IInputElement inputElement = commandSource.CommandTarget; RoutedCommand routedCommand = command as RoutedCommand; if (routedCommand != null) { if (inputElement == null) { inputElement = (commandSource as IInputElement); } return(routedCommand.CanExecute(commandParameter, inputElement)); } return(command.CanExecute(commandParameter)); }
private void _InvokeCommand() { ICommand command = this.Command; if (command != null) { object commandParameter = this.CommandParameter; IInputElement commandTarget = this.CommandTarget; RoutedCommand command2 = command as RoutedCommand; if (command2 != null) { if (command2.CanExecute(commandParameter, commandTarget)) { command2.Execute(commandParameter, commandTarget); } } else if (command.CanExecute(commandParameter)) { command.Execute(commandParameter); } } }
private bool CanExecuteCommandSource(ICommandSource commandSource) { ICommand command = commandSource.Command; if (command == null) { return(false); } object commandParameter = commandSource.CommandParameter; IInputElement commandTarget = commandSource.CommandTarget; RoutedCommand command2 = command as RoutedCommand; if (command2 == null) { return(command.CanExecute(commandParameter)); } if (commandTarget == null) { commandTarget = commandSource as IInputElement; } return(command2.CanExecute(commandParameter, commandTarget)); }
private void UpdateCanExecute() { if (Command != null) { object parameter = CommandParameter; IInputElement target = CommandTarget; RoutedCommand routed = Command as RoutedCommand; if (routed != null) { CanExecute = routed.CanExecute(parameter, target); } else { CanExecute = Command.CanExecute(parameter); } } else { CanExecute = true; } }
/// <summary> /// Executes a given command if its <see cref="ICommand.CanExecute"/> method /// indicates it can run. /// </summary> /// <param name="command">The command to be executed, or a null reference.</param> /// <param name="commandParameter">An optional parameter that is associated with /// the command.</param> /// <param name="target">The target element on which to raise the command.</param> public static void ExecuteIfEnabled(this ICommand command, object commandParameter, IInputElement target) { if (command == null) { return; } RoutedCommand rc = command as RoutedCommand; if (rc != null) { //routed commands work on a target if (rc.CanExecute(commandParameter, target)) { rc.Execute(commandParameter, target); } } else if (command.CanExecute(commandParameter)) { command.Execute(commandParameter); } }
private void Command_CanExecuteChanged(object sender, EventArgs e) { if (Command != null) { RoutedCommand command = Command as RoutedCommand; // RoutedCommand. if (command != null) { IInputElement inputElt = CommandTarget; if (inputElt == null) { inputElt = this; } if (command.CanExecute(CommandParameter, inputElt)) { IsEnabled = true; } else { IsEnabled = false; } } // Not a RoutedCommand. else { if (Command.CanExecute(CommandParameter)) { IsEnabled = true; } else { IsEnabled = false; } } } }
private void _InvokeCommand() { ICommand command = Command; if (command != null) { object parameter = CommandParameter; IInputElement target = CommandTarget; RoutedCommand routedCommand = command as RoutedCommand; if (routedCommand != null) { if (routedCommand.CanExecute(parameter, target)) { routedCommand.Execute(parameter, target); } } else if (command.CanExecute(parameter)) { command.Execute(parameter); } } }
public static bool ExecuteCommand(ICommand command, object parameter, IInputElement target) { if (command == null) { return(false); } RoutedCommand routed = command as RoutedCommand; if (routed != null) { if (routed.CanExecute(parameter, target)) { routed.Execute(parameter, target); return(true); } } else if (command.CanExecute(parameter)) { command.Execute(parameter); return(true); } return(false); }
bool CanExecuteRoutedCommandHandler(RoutedCommand command, object parameter) { return(command.CanExecute(parameter, this)); }
public bool CanExecute(object parameter) { return(_routedCommand.CanExecute(parameter, GetTextArea(GetEditor(parameter)))); }