public DelegateCommand <TParameter> CreateCommand <TCommandType>() where TCommandType : class, ICommand <TParameter> { TCommandType cmd = Activator.CreateInstance(typeof(TCommandType)) as TCommandType; return(new DelegateCommand <TParameter>(p => cmd.Execute(p), p => cmd.CanExecute(p))); }
/// <summary> /// Gets the instance /// </summary> /// <typeparam name="TCommandType">The command type</typeparam> /// <returns>a new command</returns> public TCommandType Get <TCommandType>() where TCommandType : CompositeCommand, new() { this._compositeCommands.TryGetValue(typeof(TCommandType), out var command); if (command == null) { command = new TCommandType(); this._compositeCommands.Add(typeof(TCommandType), command); } return((TCommandType)command); }
public DelegateCommand <TParameter> CreateCommand <TCommandType>(params object[] args) where TCommandType : class, ICommand <TParameter> { TCommandType cmd = Activator.CreateInstance(typeof(TCommandType), args) as TCommandType; DelegateCommand <TParameter> delegateCommand = new DelegateCommand <TParameter>(p => cmd.Execute(p), p => cmd.CanExecute(p)); INotifyParametersChangedCommand notifyParametersChangedCommand = cmd as INotifyParametersChangedCommand; if (notifyParametersChangedCommand != null) { WeakEventManager <INotifyParametersChangedCommand, EventArgs> .AddHandler(notifyParametersChangedCommand, nameof(notifyParametersChangedCommand.ParametersChanged), (sender, eventArgs) => delegateCommand.RaiseCanExecuteChanged()); } return(delegateCommand); }