1
votes

I began studying C# and I'm currently learning some Prism. I'm having some difficulty with the whole project structure and interfaces. Could you guys help me?

I've learned that ALL ViewModels implement inherit the BindableBase Interface. But what about the Models?

IE: I have a Employee Model. It has my Class Attributes with my Sets and Gets and the OnPropertyChanged implementation. Is that correct?

Model implements INotifyPropertyChanged and ViewModel implements inherits BindableBase?

1
I think it's important to point out that BindableBase is a base class to inherit from which is something different than implementing an interface. I'm sorry I can't answer your actual question because I'm only familiar with MVVMLight.Filburt
Your Model shall include just your class and all the functions related to it. Your ViewModel shall include all the logic. Then your View will include all the event handlers and the GUIKhalil Khalaf
Not All of your ViewModels have to extend BindableBase class (it's not an interface). BindableBase has a neat way of implementing INotifyPropertyChanged and it's up to you to use it or not. If you don't use it, nothing happens. Just implement INotifyPropertyChanged and that's it. If you decide to use it, there's no problem using it on your models either but you have to include the prism assemblies when you do so which may or may not be desirable. Source code for BindableBase: github.com/PrismLibrary/Prism/blob/master/Source/Prism/Mvvm/…kha
Thank you guys for the replies! I'm mainly using BindableBase for the SetProperty method from INotifyPropertyChanged. So... Do I implement that on my Models? If I did that, my ViewModel would inhert from nothing, right? And thank you Filburt for editing my original post.ThalesMiguel

1 Answers

1
votes

BindableBase is a base class from Prism for your viewmodels/models. This base class helps you to implement INotifyPropertyChanged and provides a SetProperty method to make sure you don't forget to trigger the event. You can implement INotifyPropertyChanged and call OnPropertyChanged methods yourself, but why bother.

You can discuss whether models should implement INotifyPropertyChanged or not (by itself, or by inheriting from BindableBase).

As soon as your data can change by either the frontend or the backend and the UI (or any other system watching the changes) needs to be notified/updated, it's easiest to implement INotifyPropertyChanged (/use BindableBase). If a certain type in your model is always readonly you could leave off the interface, but in my opinion most of the time it's not worth the trouble (what if some day it's no longer readonly and you have updating bugs).

You can read more on the MVVM pattern and INotifyPropertyChanged in particular in the Prism documentation.