Introduction to MVVM in WPF (Model View ViewModel)

Introduction:  MVVM Stands for Model, View, Model.

MVVM is software architecture for WPF and Silverlight projects.

In MVVM, project is divided into three section:

Model: Database interaction layer, if we are using the web service to interact with database, all the logic's to interact with the service layer should go into the model.

View : As the name says, View is nothing but presentation layer i.e. Xaml part in WPF is our presentation layer with which user interacts.

ViewModel: The bridge between View and Model is View Model.The properties that are used to bind the controls of View are defined and updated in the ViewModel.
The data that we need from model (database) is also passed to view by ViewModel with the help of properties.

Some important concept of MVVM :

1. INotifyPropertyChanged notifies the binding control in the view that the value of the property has been changed and controls reflects the changed values.


2. Relay Command: Relay commands are implemented used ICommand for e.g.

As we not do any code in cs page in MVVM approach, So how would View tell ViewModel that an event has been fired.That event needs to bind by ICommand.

3. DataContext:  DataContext tells the relation of View and ViewModel, For e.g. if CustomerView is created, then how would it come to know that to which viewmodel it would bind, DataContext is used to define that relation between View and ViewModel.



Let's understand the above concepts by using sample application in our next blog.




Comments

Popular Posts

How to position controls using Canvas control in WPF using MVVM

Change font and size in visual studio

JWTs in ASP.NET Core 2.0