Posts

Showing posts with the label mvvm-architect

Events Interactivity in WPF MVVM

Image
In our last Article we have learned to create a sample application using WPF MVVM pattern including Inotify properties, Relay commands,Button click events. In this article , we will learn how to fire other events in MVVM, for example if we need to  fire double mouse click in WPF, we just need to create a new event handle on doublemouse click event but in MVVM it is not the case, because we cannot dorectly write the code for events in .cs  form.So we  need to use the RelayCommands for these events also, same as we have use dfor signle button click. So if  we bind a command of button to a relay command, by default it would call a Singleleftmouseclick, but what we need to bind that command to doublemouseleftclick. So for handling these types of events in MVVM we use :System.Windows.Interactivity; Lets see how to use that: Step 1: Just add a button control in MainWindow.xaml . Step 2: Add reference  "System.Windows.Interactivity" to solution explorer=>r...

Sample application using MVVM in WPF

Image
As we have already learned the basics of MVVM pattern in previous session, Lets  now understood each of them in practical by creating a sample application. Lets create a sample WPF application, below are the steps: 1. Open visual studio and click on new project and select Windows under c# and select WPF Application from the list in center, click ok and you have created a WPF Project. 2. Now, we will focus on the View, ViewModel and Inotify , Relay commands and see how they work in practical. 3. Windows are Usercontrols that contains XAML part comes under VIEW category.In above created project you can see the Default MainWindow, this is View for our project or any other window or User control that you will be adding to project would come under View.

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 implement...