Get notified when properties change in the Model

后端 未结 4 856
-上瘾入骨i
-上瘾入骨i 2021-01-27 05:16

There seems to be conflicting thoughts on whether INotifyPropertyChanged should be implemented in the Model or not. I think that it should be implemented in the Vie

4条回答
  •  花落未央
    2021-01-27 05:45

    Interesting question. I've read about MVVM for more than a year now, and I'm still not sure about it.

    If your application is representing a state of a process for example, and this state is modified internally without any interaction of the user, then your model needs to be able to notify your viewmodel that it changed. So if your model implement INotifyPropertyChanged, and your viewmodel only pass the same informations to the view, then... does your viewmodel really need to exist...?

    In our company, we consider two main cases:

    • We structure our software with a quite strict UML analysis before developping (not so agile). When we then want to display our objects on screen, they return us their different views, which are used when needed with Bindings (using ContentControl or so). Most of the views we need for our software display these kinds of object, that implement INotifyPropertyChanged and are therefore also kind of ViewModels.

    • To build the software main Views (view structure), we create global views and ViewModels for them. That's when we really follow the MVVM practices.

    Maybe I missed a point about MVVM, but in my experience, it's not a pattern that you absolutely have to always follow. It's a very good way of thinking to develop WPF applications, but creating ViewModels for each and every view seems to me like a big overhead.

    What do all of you think of this way of doing?

    Best regards,

    Antoine

    EDIT 31.03.2012

    I have found a very interesting article explaining how to handle your model properties in the viewmodel, without having to implement a proxy property in the viewModel for each one of them. Also the writer say some words about having INPC implemented in the model, and the viewmodel listening to it. I think this is the most practical oriented article I've read about MVVM so far. Check it out : http://msdn.microsoft.com/en-us/magazine/ff798279.aspx

提交回复
热议问题