Windows Phone App with MVVM design patten

Preview:

DESCRIPTION

This slides describes about how to create a Windows Phone application with MVVM design pattern.

Citation preview

/* Life runs on code */

UNDERSTANDING THE MODEL-VIEW-VIEWMODEL

PATTERNKamalakannan AnnamalaiSenior Software Engineer

Ilink-Systemshttp://kamalakannana.wordpress.com

WHAT IS MVVM?

• A weird acronym– Model – View – ViewModel

• Woven into WPF/SL/WP• Some confusion:– MVVM is really just the pattern– The rest are helpers, practices, etc.

• Why does MVVM pattern is best for WPF/SL/WP?

-WPF/SL/WP Controls are developed using MVVM internally.

THE MVC PATTERN

Model View

Controller

THE PASSIVE VIEW PATTERN

Model View

Controller

THE PRESENTATION MODEL PATTERN

Model View

Presentation Model

(ViewModel)

DataBinding

BLENDABILITY

• Testability, Maintainability, Blendability

• “The ability to be edited in Blend”

– (and Visual Studio designer…)

• Differentiate code in design and runtime

• Create design time data

/* Life runs on code */ 7

BRIDGING THE GAP

/* Life runs on code */ 8

View

ViewModel

DataBinding Commands Messages

Model

BRIDGING THE GAP

/* Life runs on code */ 9

View

ViewModelView

ViewModel

View

ViewModel

DEMO

© 2010 IdentityMine Inc. All Rights Reserved. 10Page:

Hello MVVM(and Hi Blend)

COMMANDS

• “Point of entry” for a method• Can be data bound• ICommand interface–Execute method–CanExecute method–CanExecuteChanged event

/* Life runs on code */ 11

FLAWS OF MVVM

• Too much code needed– INotifyPropertyChanged–Commands

• Some operations are tricky (set focus…)

• Not applicable to ASP.NET, etc• Message to community is not clear

/* Life runs on code */ 12

DEBUNK THE MYTHS

• “No code in the code behind”– “If you put code in the View's code-behind, the

MVVM police will take your family away”– “No need for converters”

• “MVVM is suitable for big projects”• “MVVM costs performance”• “MVVM is complex / makes my head

hurt”

/* Life runs on code */ 13

DEBUNK THE MYTHS

• “I don’t need separation because I don’t have a designer”

• “You cannot use MVVM with other patterns”

• “MVVM will make you rich and attractive”

/* Life runs on code */ 14

MVVM LIGHT TOOLKIT

• “Breaking the monotony”• http://www.galasoft.ch/mvvm/getstar

ted• http://mvvmlight.codeplex.com• Keep it small• Keep it simple

/* Life runs on code */ 15

MVVM LIGHT TOOLS

• Project templates (VS + Blend)• Item templates (VS + Blend)• Code snippets

/* Life runs on code */ 16

THANKS!/* Life runs on code

*/