17
/* Life runs on code */

Windows Phone App with MVVM design patten

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: Windows Phone App with MVVM design patten

/* Life runs on code */

Page 2: Windows Phone App with MVVM design patten

UNDERSTANDING THE MODEL-VIEW-VIEWMODEL

PATTERNKamalakannan AnnamalaiSenior Software Engineer

Ilink-Systemshttp://kamalakannana.wordpress.com

Page 3: Windows Phone App with MVVM design patten

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.

Page 4: Windows Phone App with MVVM design patten

THE MVC PATTERN

Model View

Controller

Page 5: Windows Phone App with MVVM design patten

THE PASSIVE VIEW PATTERN

Model View

Controller

Page 6: Windows Phone App with MVVM design patten

THE PRESENTATION MODEL PATTERN

Model View

Presentation Model

(ViewModel)

DataBinding

Page 7: Windows Phone App with MVVM design patten

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

Page 8: Windows Phone App with MVVM design patten

BRIDGING THE GAP

/* Life runs on code */ 8

View

ViewModel

DataBinding Commands Messages

Model

Page 9: Windows Phone App with MVVM design patten

BRIDGING THE GAP

/* Life runs on code */ 9

View

ViewModelView

ViewModel

View

ViewModel

Page 10: Windows Phone App with MVVM design patten

DEMO

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

Hello MVVM(and Hi Blend)

Page 11: Windows Phone App with MVVM design patten

COMMANDS

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

/* Life runs on code */ 11

Page 12: Windows Phone App with MVVM design patten

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

Page 13: Windows Phone App with MVVM design patten

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

Page 14: Windows Phone App with MVVM design patten

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

Page 15: Windows Phone App with MVVM design patten

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

Page 16: Windows Phone App with MVVM design patten

MVVM LIGHT TOOLS

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

/* Life runs on code */ 16

Page 17: Windows Phone App with MVVM design patten

THANKS!/* Life runs on code

*/