You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
|
|
|
|
namespace MVVMDemo
|
|
|
|
|
{
|
|
|
|
|
// 这个RelayCommand只要继承了ICommand,实现接口就可以了
|
|
|
|
|
// 至于你怎么定义构造,怎么实现,都是你自己的事情
|
|
|
|
|
public class RelayCommand : ICommand
|
|
|
|
|
{
|
|
|
|
|
private readonly Predicate<object> _canExecute;
|
|
|
|
|
private readonly Action<object> _execute;
|
|
|
|
|
|
|
|
|
|
public RelayCommand(Predicate<object> canExecute, Action<object> execute)
|
|
|
|
|
{
|
|
|
|
|
this._canExecute = canExecute;
|
|
|
|
|
this._execute = execute;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public event EventHandler CanExecuteChanged
|
|
|
|
|
{
|
|
|
|
|
add { CommandManager.RequerySuggested += value; }
|
|
|
|
|
remove { CommandManager.RequerySuggested -= value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool CanExecute(object parameter)
|
|
|
|
|
{
|
|
|
|
|
return _canExecute(parameter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Execute(object parameter)
|
|
|
|
|
{
|
|
|
|
|
_execute(parameter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|