Transcript

MVVM SESSION

CONTENTS• Prerequisites

• What is MVVM?

• Elements of MVVM

• Architectural Diagram

• Why we need MVVM?

• What is INotifyPropertyChanged Interface?

• What is Icommand Interface?

• Pros & Cons

• Practical Implementation

• Supported Frameworks & References

BASICS AND KEY POINTS TO KNOW

• Xaml

• Data Binding

• Key Concepts

1.observablecollection

2.INotifyPropertyChanged

3.ICommand

MVVM(MODEL, VIEW, VIEWMODEL)

• is an architectural pattern created by John Gossman from WPF team

• is a variation of MVC pattern

• Also known as Presentation model

• Woven into WPF/SL

• WPF Data Binding & Commanding

ELEMENTS OF MVVM

• Model : Business Logic

• View : UI logic

• ViewModel : Presentational Logic

ARCHITECTURAL DIAGRAM

NEED OF MVVM

To Avoid Glue Code

RULES OF MVVM COMPLIANT APPLICATIONS

• Minimum Code Behind (Recommended No code Behind)

• Events as Commands

• ViewModel as DataContext

• Design View and ViewModel Independently

INOTIFYPROPERTYCHANGED

•  any class that implements this interface, notifies any listeners when a property has changed. 

• Notifies clients that a property value has changed.

• To implement INotifyPropertyChanged you need to declare the PropertyChanged event and create the OnPropertyChanged method. Then for each property you want change notifications for, you call OnPropertyChanged whenever the property is updated.

ICOMMAND

• Methods

1.CanExecute (Defines the method that determines whether the command can execute in its current state.)

2.Execute(Defines the method to be called when the command is invoked.)

• Events

1.CanExecuteChanged (Occurs when changes occur that affect whether or not the command should execute.)

OBSERVABLECOLLECTION

An ObservableCollection is a dynamic collection of objects of a given type.

When an object is added to or removed from an observable collection, the UI is automatically updated.

WPF automatically adds a CollectionChanged event handler to the ObservableCollecion's events.

public class ObservableCollection<T> : Collection<T>, INotifyCollectionChanged, INotifyPropertyChanged

PROS & CONS

• Cons

Ease of Maintainance

Ease of Testing

Flexibility

Re Usability

Low Degree of coupling

• Pros

Not Suitable for Simple Applications (Need best coding practices and standards)

Not a standardized one , Everyone follows their own flavours

PRACTICAL IMPLEMENTATION

SUPPORTED FRAMEWORKS AND REFERENCES• WPF Team : MVVM Toolkit• MS Pattern and Practice Team : Composite WPF (Prism)• Josh Smith. "MVVM Foundation"• Sacha Barber. "Cinch."• Karl Shifflett. "Ocean"• Laurent Bugnion. "MVVM Light Toolkit"• Lester Lobo. "CoreMVVM"• Rob Eisenberg. "Caliburn"• William e Kempf. "Onyx"• Peter O’Hanlon. "GoldLight"• jbe. "WPF Application Framework (WAF)"• Paul Stovel : MacroModelsReferences: http://www.codeproject.com/Articles/659614/MVVM-in-Depthhttp://www.codeproject.com/Articles/165368/WPF-MVVM-Quick-Start-Tutorial (For Practical Implementation)

top related