MVVM Madness: Commands

后端 未结 7 1079
星月不相逢
星月不相逢 2021-01-30 01:38

I like MVVM. I don\'t love it, but like it. Most of it makes sense. But, I keep reading articles that encourage you to write a lot of code so that you can write XAML and don\'t

7条回答
  •  囚心锁ツ
    2021-01-30 02:10

    Decoupling is one of the major feature of MVVM. If suppose you want to change say view or binded model to it. How much easy it is for your application?

    Take an example where View1 and View2 both share the same ViewModel. Now will you implement the code behind method for both.

    Also, suppose if you need to change the viewmodel for a view on later stage your command will get fail as view model is changed and statement

    MyViewModel vm = this.DataContext as MyViewModel;
    

    will return null and hence code crash. So there comes an extra burden to change the code behind also. These kind of scenarios will arise if you do it in this way.

    Of course there are many ways to achieve the same thing in programming but which one is best will lead to best approach.

提交回复
热议问题