Why use a RelayCommand or DelegateCommand instead of just implementing ICommand?

前端 未结 2 1227
半阙折子戏
半阙折子戏 2021-01-05 04:21

I\'m just learning about MVVM in WPF, I\'m completely new both to WPF as to MVVM (I understand how it works, but have never used it...)

Every single tutorial/article

相关标签:
2条回答
  • 2021-01-05 04:35

    Nothing ... but DelegateCommand is useful if you have a really specific Command just for your ViewModel and you don't want to expose it to others because it is really just for your ViewModel. Also i like DelegateCommands because they don't need another class which you just pass in your ViewModel, it is less code to write. Your approach is useful if your supplied ViewModel is a base ViewModel which is shared alot which also allows sharing your Command.

    0 讨论(0)
  • 2021-01-05 04:55

    If you won't use some base command (of a framework or your own custom command) you'll find yourself writing the same code over and over again. For example: you don't raise CanExecuteChanged event in your own command. The same goes for implementing INotifyPropertyChanged. That's why everyone's using one or another MVVM framework.

    0 讨论(0)
提交回复
热议问题