MVVM Routed and Relay Command

后端 未结 4 1526
萌比男神i
萌比男神i 2020-11-30 19:39

What is the Difference between the RoutedCommand and RelayCommand ? When to use RoutedCommand and when to use RelayCommand in MVVM pattern ?

4条回答
  •  生来不讨喜
    2020-11-30 19:46

    The difference is that RelayCommand can accept delegates. You can define the RelayCommand outside of the ViewModel. The ViewModel can then add delegates to the command when it creates and binds the command to an UI object like a control. The delegates in turn can access the private variable of the ViewModel as they are defined in the scope of the View Model itself.

    It is used to cut down on the amount of code contained in the ViewModel as the trend is to define a Routed command as a nested class inside the ViewModel. The functionality of the two is otherwise similar.

提交回复
热议问题