private static void RaiseCanExecute(IntPtr cPtr, IntPtr sender, IntPtr e) { try { if (!_CanExecute.ContainsKey(cPtr)) { throw new InvalidOperationException("Delegate not registered for CanExecute event"); } if (sender == IntPtr.Zero && e == IntPtr.Zero) { _CanExecute.Remove(cPtr); return; } if (Noesis.Extend.Initialized) { CanExecuteHandler handler = _CanExecute[cPtr]; if (handler != null) { handler(Noesis.Extend.GetProxy(sender, false), new CanExecuteRoutedEventArgs(e, false)); } } } catch (Exception exception) { Noesis.Error.SetNativePendingError(exception); } }
/// <inheritdoc cref="RelayCommand(ExecuteHandler, CanExecuteHandler)"/> /// <param name="dispatcher">Диспетчер.<br/> Событие <see cref="ICommand.CanExecuteChanged"/> /// бyдет создаваться в нём,<br/> независимо от того в каком потоке был вызван /// метод <see cref="ICommandInvalidate.Invalidate"/>.<br/> /// Если dispatcher = null, то диспетчер будет получен от <see cref="Application.Current"/>.</param> public WpfRelayCommand(ExecuteHandler execute, CanExecuteHandler canExecute = null, Dispatcher dispatcher = null) : this(dispatcher) { this.execute = execute ?? throw new ArgumentNullException(nameof(execute)); this.canExecute = canExecute ?? CanExecuteTrue; }
public BaseCustomCommand( CanExecuteHandler canExecuteAction = null, bool handleExceptions = false, ViewModelBase parent = null, bool autoCanExecute = false, string groupName = null) { CanExecuteAction = canExecuteAction; HandleExceptions = handleExceptions; Parent = parent; AutoCanExecute = autoCanExecute; GroupName = groupName; if (AutoCanExecute) { if (canExecuteAction != null) { CanExecuteAction = () => !InProgress && canExecuteAction(); } else { CanExecuteAction = () => !InProgress; } } else { CanExecuteAction = canExecuteAction; } }
/// <summary>Конструктор команды</summary> /// <param name="executeT">Выполняемый метод команды</param> /// <param name="canExecuteT">Метод разрешающий выполнение команды</param> public RelayCommand(ExecuteHandler <T> executeT, CanExecuteHandler <T> canExecuteT = null) { execute = ExecuteT; canExecute = CanExecuteT; this.executeT = this.executeT ?? throw new ArgumentNullException(nameof(executeT)); this.canExecuteT = this.canExecuteT ?? CanExecuteTrue; }
/// <summary>Конструктор команды</summary> /// <param name="execute">Выполняемый метод команды</param> /// <param name="canExecute">Метод разрешающий выполнение команды</param> public RelayCommand(ExecuteHandler execute, CanExecuteHandler canExecute = null) { _onExecute = execute; _canExecute = canExecute; _requerySuggested = (o, e) => Invalidate(); CommandManager.RequerySuggested += _requerySuggested; }
/// <inheritdoc cref="RelayCommand(ExecuteHandler{object}, CanExecuteHandler{object})"/> public RelayCommand(ExecuteHandler execute, CanExecuteHandler canExecute = null) : this ( p => execute(), p => canExecute?.Invoke() ?? true ) { }
/// <inheritdoc cref="WpfRelayCommand(ExecuteHandler, CanExecuteHandler, Dispatcher)"/> public WpfRelayCommand(ExecuteHandler <T> execute, CanExecuteHandler <T> canExecute = null, Dispatcher dispatcher = null) : base(dispatcher) { base.execute = ExecuteT; base.canExecute = CanExecuteT; executeT = execute ?? throw new ArgumentNullException(nameof(execute)); canExecuteT = canExecute ?? CanExecuteTrue; }
/// <summary>Конструктор команды.</summary> /// <param name="execute">Выполняемый метод команды.</param> /// <param name="canExecute">Метод, возвращающий состояние команды.</param> public RelayCommand(ExecuteHandler execute, CanExecuteHandler canExecute = null) : this() { this.execute = execute ?? throw new ArgumentNullException(nameof(execute)); this.canExecute = canExecute; requerySuggested = (o, e) => Invalidate(); CommandManager.RequerySuggested += requerySuggested; }
/// <inheritdoc cref="RelayCommand{T}(ExecuteHandler{T}, CanExecuteHandler{T}, ConverterFromObjectHandler{T})"/> public RelayCommandAsync(ExecuteHandler <T> execute, CanExecuteHandler <T> canExecute, ConverterFromObjectHandler <T> converter = null) : base ( p => { if (p is T t || (converter != null && converter(p, out t))) { execute(t); }
/// <inheritdoc cref="RelayCommand(ExecuteHandler, CanExecuteHandler)"/> public RelayCommand(ExecuteHandler <T> execute, CanExecuteHandler <T> canExecute = null) : base ( p => { if (p is T t) { execute(t); } }, p => (p is T t) && (canExecute?.Invoke(t) ?? true)
public AsyncCustomCommand( ExecuteAsyncHandlerWithParam executeAction, CanExecuteHandler canExecuteAction = null, bool handleExceptions = false, ViewModelBase parent = null, bool autoCanExecute = false, string groupName = null) : base(canExecuteAction, handleExceptions, parent, autoCanExecute, groupName) { executeAction.NotNull("execute"); ExecuteAsyncActionWithParam = executeAction; }
public bool CanExecute(object parameter = null) { if (!m_enabled) { return(false); } var canExecute = CanExecuteHandler?.Invoke(parameter); //either no handler (enabled) or use value returned by handler return(!canExecute.HasValue || canExecute.Value); }
/// <inheritdoc cref="AsyncData(ExecuteHandler, CanExecuteHandler)"/> public AsyncData(ExecuteHandler <object> execute, CanExecuteHandler <object> canExecute) { this.execute = execute ?? throw new ArgumentNullException(nameof(execute)); if (canExecute == null) { CanExecuteAsync = canExecuteNullAsync; } else { this.canExecute = canExecute; CanExecuteAsync = canExecuteAsync; } }
/// <summary> /// Defines the method that determines whether the command can execute in its current state. /// </summary> /// <param name="parameter">Data used by the command. If the command does not require data to be passed, this object can be set to null.</param> /// <returns> /// true if this command can be executed; otherwise, false. /// </returns> public bool CanExecute(object parameter) { WindowCanExecuteArgs args = new WindowCanExecuteArgs((parameter as Window) ?? Window, parameter); if (args.Window != null) { CanExecuteHandler temp = OnCanExecute; if (temp != null) { temp(this, args); } else { IfNoHandlerOnCanExecute(this, args); } } return(args.CanExecute); }
/// <summary>Creates an instance.</summary> /// <param name="execute">Synchronous Execute method.</param> /// <param name="canExecute">Synchronous CanExecute method.</param> public AsyncData(ExecuteHandler execute, CanExecuteHandler canExecute) { if (execute == null) { throw new ArgumentNullException(nameof(execute)); } this.execute = p => execute(); if (canExecute == null) { CanExecuteAsync = canExecuteNullAsync; } else { this.canExecute = p => canExecute(); CanExecuteAsync = canExecuteAsync; } }
private static void RaiseCanExecute(IntPtr cPtr, IntPtr sender, IntPtr e) { try { if (Noesis.Extend.Initialized) { long ptr = cPtr.ToInt64(); if (sender == IntPtr.Zero && e == IntPtr.Zero) { _CanExecute.Remove(ptr); return; } CanExecuteHandler handler = null; if (!_CanExecute.TryGetValue(ptr, out handler)) { throw new InvalidOperationException("Delegate not registered for CanExecute event"); } handler?.Invoke(Noesis.Extend.GetProxy(sender, false), new CanExecuteRoutedEventArgs(e, false)); } } catch (Exception exception) { Noesis.Error.UnhandledException(exception); } }
public bool CanExecute(object parameter) => CanExecuteHandler?.Invoke(parameter) ?? true;
public DelegateCommand(ExecuteHandler aExecute, CanExecuteHandler aCanExecute, object aOverwriteParameter) { mExecute = aExecute; mCanExecute = aCanExecute; mOverwriteParameter = aOverwriteParameter; }
public DelegateCommand(ExecuteHandler aExecute, CanExecuteHandler aCanExecute) : this(aExecute, aCanExecute, null) { }
public ShellRelayCommand(ExecuteHandler executeHandler, CanExecuteHandler canExecuteHandler) { _executeHandler = executeHandler; _canExecuteHanlder = canExecuteHandler; }
/// <summary>Конструктор команды.</summary> /// <param name="execute">Выполняемый метод команды.</param> /// <param name="canExecute">Метод проверяющий состояние команды.</param> public RelayCommand(ExecuteHandler execute, CanExecuteHandler canExecute = null) { this.execute = execute ?? throw new ArgumentNullException(nameof(execute)); this.canExecute = canExecute ?? CanExecuteTrue; }
/// <inheritdoc cref="RelayCommand(ExecuteHandler, CanExecuteHandler)"/> public RelayCommandAsync(ExecuteHandler execute, CanExecuteHandler canExecute = null) : this(new AsyncData(execute, canExecute)) { }
/// <summary>Конструктор команды</summary> /// <param name="execute">Выполняемый метод команды</param> /// <param name="canExecute">Метод разрешающий выполнение команды</param> public RelayCommand(ExecuteHandler <T> execute, CanExecuteHandler <T> canExecute = null) : base(p => execute(p is T t ? t : default), p => p is T t && (canExecute?.Invoke(t) ?? true))
public WindowUICommand(string text, string name, Window window, CanExecuteHandler canExecute, ExecuteHandler execute) : this(text, name, window) { OnCanExecute += canExecute; OnExecute += execute; }
/// <summary>Конструктор команды</summary> /// <param name="execute">Выполняемый метод команды</param> /// <param name="canExecute">Метод разрешающий выполнение команды</param> public RelayCommand(ExecuteHandler execute, CanExecuteHandler canExecute = null) { this._onExecute = execute; this._canExecute = canExecute; }
/// <inheritdoc /> public TaskExecution(ExecuteHandler <object> execute, CanExecuteHandler <object> canExecute) : base(execute, canExecute) { }
/// <summary> Command constructor. </summary> /// <param name = "execute"> Command method to execute. </param> /// <param name = "canExecute"> Method that returns the state of the command. </param> public RelayCommand(ExecuteHandler <object> execute, CanExecuteHandler <object> canExecute = null) : this() { this.execute = execute ?? throw new ArgumentNullException(nameof(execute)); this.canExecute = canExecute; }