Command有两个功能:

a:执行一个特殊的行为:command的主要功能。

b:确定某一UIElement的视觉状态(visual state):例如确定button是否可用。

DelegateCommand:实现了ICommand,当需要使用command时,可用使用此类

a:CanExecuteChanged事件和CanExecute方法被用来确定command所施加控件的视觉状态,它们是这样工作的:当某command施加于某控件时,控件会调用CanExecute方法,来确定初始的视觉状态,假设调用者是button,如果CanExecute方法返回false,button会被禁用。button同时也会订阅CanExecuteChanged事件。当触发CanExecuteChanged事件时,会再次调用CanExecute以确定是否需要修改视觉状态。

b:Execute方法比较直白:当需要执行某些行为操作时,控件会调用它。例如,当按下按钮时。


相关文章:

  • 2021-09-12
  • 2022-01-03
  • 2021-09-01
  • 2022-03-04
  • 2022-12-23
  • 2021-05-05
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
  • 2022-12-23
  • 2021-06-27
  • 2021-10-17
相关资源
相似解决方案