/// <summary> /// Initializes a new instance of the RelayCommand class. /// </summary> /// <param name="execute">The execution logic. IMPORTANT: If the action causes a closure, /// you must set keepTargetAlive to true to avoid side effects. </param> /// <param name="canExecute">The execution status logic. IMPORTANT: If the func causes a closure, /// you must set keepTargetAlive to true to avoid side effects. </param> /// <param name="keepTargetAlive">If true, the target of the Action will /// be kept as a hard reference, which might cause a memory leak. You should only set this /// parameter to true if the action is causing a closures. See /// http://galasoft.ch/s/mvvmweakaction. </param> /// <exception cref="ArgumentNullException">If the execute argument is null.</exception> public RelayCommand(Action execute, Func <bool> canExecute, bool keepTargetAlive = false) { if (execute == null) { throw new ArgumentNullException("execute"); } _execute = new WeakAction(execute, keepTargetAlive); if (canExecute != null) { _canExecute = new WeakFunc <bool>(canExecute, keepTargetAlive); } }