21
Getting started with MVVM Model-View-ViewModel Ash Tewari www.ashtewari.com @ashtewari

Getting started with MVVM

Embed Size (px)

DESCRIPTION

Slidedeck from "Getting Started with MVVM" presentation at RDU Code Camp 2010.

Citation preview

Page 1: Getting started with MVVM

Getting started with MVVMModel-View-ViewModel

Ash Tewariwww.ashtewari.com

@ashtewari

Page 2: Getting started with MVVM

2

Introductions

• Introductions• Announcements• Share contact information

Page 3: Getting started with MVVM

3

Survey

• Do you work with WPF or Silverlight ?• How familiar are you with MVVM ?– Heard about it– Read about it– Played around with it– Used it in a production application

Page 4: Getting started with MVVM

4

Stupid Questions Policy

Page 5: Getting started with MVVM

5

Why ?

WPF Features– Data Binding– Data Templates– Resources– Commands

Page 6: Getting started with MVVM

6

Why ?

Decouple View from its State and Behavior – Code is easy to understand, maintain, evolve and troubleshoot

Page 7: Getting started with MVVM

7

Why ?

Testability – Automated Regressions

Page 8: Getting started with MVVM

8

Why ?

Easily skin user interfaces

Page 9: Getting started with MVVM

9

Why ?

Designer/Developer Workflow – Allows Specialists to work on the same project without much friction

Page 10: Getting started with MVVM

10

Sample Application

• MSDN Magazine Article :

http://msdn.microsoft.com/en-us/magazine/dd419663.aspx

• Sample Application Download:

http://code.msdn.microsoft.com/mag200902MVVM/Release/ProjectReleases.aspx

Page 11: Getting started with MVVM

11

Demo

Structure of demo application

Page 12: Getting started with MVVM

12

M-V-VM

• Model• View• ViewModel

Page 13: Getting started with MVVM

13

Demo

Add “Search” feature to the demo application

Page 14: Getting started with MVVM

14

Take Away

Model does not know about View and ViewModel.

Page 15: Getting started with MVVM

15

Take Away

ViewModel is an abstraction of the View. It encapsulates the State as well as the behavior of the View.

Page 16: Getting started with MVVM

16

Take Away

ViewModel does not have a reference to the View.

Page 17: Getting started with MVVM

17

Take Away

ViewModel implements INotifyPropertyChanged.

Page 18: Getting started with MVVM

18

Take Away

ViewModel is assigned to the DataContext property of the View.

Page 19: Getting started with MVVM

19

Resources

• Advanced MVVM Book– http://joshsmithonwpf.wordpress.com/advanced-

mvvm/

• BubbleBurst Sample Application– http://bubbleburst.codeplex.com/

Page 20: Getting started with MVVM

20

Resources

• Comparison of MVVM Frameworks– http://www.japf.fr/2009/11/discover-compare-exi

sting-mvvm-frameworks/

• MVVM Light Toolkit– http://www.galasoft.ch/mvvm/getstarted/

Page 21: Getting started with MVVM

Feedback Forms

Ash Tewariwww.ashtewari.com

@ashtewari