Beispiel #1
0
        public DelegateCommandImpl(Action <TParameter> execute, Func <TParameter, bool> canExecute, INotifyPropertyChanged target, string[] propertyNames)
        {
            _execute       = execute;
            _canExecute    = canExecute;
            _propertyNames = propertyNames;

            if (target != null)
            {
                _propertyChangedRegistration = target.RegisterPropertyChangedWeak(this, (t, s, e) => t.OnPropertyChanged(e));
            }
        }
        /// <summary>
        /// Initializes a new instance of <see cref="DelegateCommand"/>.
        /// </summary>
        /// <param name="execute">The execute function.</param>
        /// <param name="canExecute">The canExecute function.</param>
        /// <param name="target">The object to observe for change notifications.</param>
        /// <param name="propertyNames">The property names.</param>
        public DelegateCommand(Action execute, Func <bool> canExecute, INotifyPropertyChanged target, params string[] propertyNames)
        {
            if (execute == null)
            {
                throw new ArgumentNullException(nameof(execute));
            }
            if (canExecute == null)
            {
                throw new ArgumentNullException(nameof(canExecute));
            }
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (propertyNames == null || propertyNames.Length == 0)
            {
                throw new ArgumentNullException(nameof(propertyNames));
            }

            _execute       = execute;
            _canExecute    = canExecute;
            _propertyNames = propertyNames;
            _propertyChangedRegistration = target.RegisterPropertyChangedWeak(this, (t, s, e) => t.OnPropertyChanged(e));
        }