自定义MVVM 测试

internal class DelegateCommand : ICommand
{
public event EventHandler CanExecuteChanged;

public bool CanExecute(object parameter)
{
return CanExecuteFunc == null ? true : CanExecuteFunc(parameter);
}

public void Execute(object parameter)
{
ExecuteAction?.Invoke(parameter);
}

public Action<object> ExecuteAction { get; set; }

public Func<object, bool> CanExecuteFunc { get; set; }

public DelegateCommand(Action executeMethod)
: this(executeMethod, () => true)
{
}

public DelegateCommand(Action executeMethod, Func<bool> canExecuteMethod)
{
if (executeMethod == null || canExecuteMethod == null)
{
throw new ArgumentNullException("executeMethod");
}

this.ExecuteAction = delegate
{
executeMethod();
};
this.CanExecuteFunc = (object o) => canExecuteMethod();
}


public void Execute()
{
Execute(null);
}


public bool CanExecute()
{
return CanExecute(null);
}

}

 

 

 

public abstract class NotificationObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void RaisePropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

}

posted @ 2022-06-07 22:58  小痞子Yang  阅读(67)  评论(0编辑  收藏  举报