MVVM의 ViewModelBase 및 CommandBase
6479 단어 command
1 public class ViewModelBase : INotifyPropertyChanged , IDisposable
2 {
3 public virtual string DisplayName { get; protected set; }
4
5 public event PropertyChangedEventHandler PropertyChanged;
6
7 protected void OnPropertyChanged([CallerMemberName]string propertyName = null)
8 {
9 if (PropertyChanged != null)
10 {
11 PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
12 }
13 }
14
15 public void Dispose()
16 {
17 this.OnDispose();
18 }
19
20 /// <summary>
21 /// IDisposable, , Dispose 。
22 /// </summary>
23 protected virtual void OnDispose()
24 {
25
26 }
27 }
public class CommandBase : ICommand
{
private readonly Action<object> _command;
private readonly Func<object, bool> _canExecute;
public CommandBase(Action<object> command, Func<object, bool> canExecute)
{
if (command == null)
throw new ArgumentNullException("command");
_canExecute = canExecute;
_command = command;
}
public bool CanExecute(object parameter)
{
if (_canExecute == null)
return true;
return _canExecute(parameter);
}
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public void Execute(object parameter)
{
_command(parameter);
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
peco의 쉽고 편리한 사용법가자. | peco 를 사용하여 검색한 파일/디렉토리에 cd, ls, rm, cat, vim 한다. 각각 별칭으로 쉽게 사용할 수 있도록 한다. lsp, vimp, catp 등도 마찬가지로 검색해, 각각의 액션을 실...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.