18
mvvm applied From Silverlight to Windows Phone to Windows 8 Lauren t Bugnio n Senior Director, Europe IdentityMine

MVVM Applied: From Silverlight to Windows Phone to Windows 8

Embed Size (px)

DESCRIPTION

More info on http://www.techdays.be.

Citation preview

Page 1: MVVM Applied: From Silverlight to Windows Phone to Windows 8

mvvm appliedFrom Silverlight to Windows Phone to Windows 8

LaurentBugnionSenior Director, EuropeIdentityMine

Page 2: MVVM Applied: From Silverlight to Windows Phone to Windows 8

Session Contents• A bit of recapitulation• Code code code

Disclaimer:• I am NOT a Microsoft employee and all opinions

expressed are solely my own.

Page 3: MVVM Applied: From Silverlight to Windows Phone to Windows 8

a brief recap

THE MVVM PATTERN

Page 4: MVVM Applied: From Silverlight to Windows Phone to Windows 8

Interactions: From MVC to MVVM

View

ViewModel

DataBinding CommandsMessages

Model

View Service

Events

PropertyChangedModel View

Controller

The MVC pattern:

Page 5: MVVM Applied: From Silverlight to Windows Phone to Windows 8

Interactions: VM to View, Behaviors

BehaviourBinding

ViewModel View

Page 6: MVVM Applied: From Silverlight to Windows Phone to Windows 8

Interactions: VM to View (Win8)

Binding

ViewModel View

No behaviors in Windows 8 workaround: Use properties and binding PropertyChanged event

PropertyChanged

Page 7: MVVM Applied: From Silverlight to Windows Phone to Windows 8

Interactions: View Services

ViewModel ISelectFilesService

View

injection

INavigationService

injection

actionNavigationService

Page 8: MVVM Applied: From Silverlight to Windows Phone to Windows 8

translating to metro

Page 9: MVVM Applied: From Silverlight to Windows Phone to Windows 8

What are Metro apps, actually?

Probably not a replacement for “desktop apps”Very similar to Windows Phone appsSuspended when not in the foregroundLifetime managementRun in a sandbox, declared capabilitiesPurchased in application store

A companion for your richer application

Page 10: MVVM Applied: From Silverlight to Windows Phone to Windows 8

Asynchronous

Maybe the most difficult aspectawait/async can be confusingThis is making asynchronous code easierBUT it is NOT synchronous code anyway!

Often used in Win8File system accessStream operations…

public async void Get(Uri uri){ var request = new HttpRequestMessage( HttpMethod.Post, uri); var response = await Client.SendAsync(request); var result = response.Content.ReadAsString();}

Page 11: MVVM Applied: From Silverlight to Windows Phone to Windows 8

Abstract the differences

Use callbacks to async codeUse interfaces even for simple model classes

Eg: FileInfo in .NET 4 StorageFile in Windows 8

Share common classes, overload other classesExtend classes

Partial classesExtension methods

And if you have to#if WIN8

Page 12: MVVM Applied: From Silverlight to Windows Phone to Windows 8

DemoMVVM in Silverlight, Windows Phone, Windows 8

Page 13: MVVM Applied: From Silverlight to Windows Phone to Windows 8

Session Summary• MVVM is still the key in XAML Metro apps• Same principles, same skills as Silverlight• Design time data for the tools• Clean decoupled architecture

• Porting an app means some work and some planning!• Mostly new XAML• More asynchronous code (async/await)

Page 14: MVVM Applied: From Silverlight to Windows Phone to Windows 8

call to action• Check your code for possible

asynchronous workflows• File operations• Opening streams• Use callbacks

• Check the developer preview• Stay tuned for the beta!

Page 15: MVVM Applied: From Silverlight to Windows Phone to Windows 8

Be what’s next: Windows 8 Metro Apps• Find everything here

http://aka.ms/mbl-win8• Save the date! March 23: Windows 8 Developer Day

and “Nacht van Windows 8 / La Nuit de Windows 8 (app-a-thon coding night)

• Start today!• Building Windows 8 blog: http://aka.ms/mbl-win8/build• Learn with Windows 8 Dev Preview: http://aka.ms/mbl-win8/devprev • Learn about Windows Store and opportunities:

http://aka.ms/mbl-win8/store

Page 16: MVVM Applied: From Silverlight to Windows Phone to Windows 8

more info athttp://blog.galasoft.ch

http://www.galasoft.ch/mvvm

@LBugnion

Page 17: MVVM Applied: From Silverlight to Windows Phone to Windows 8

Q&A

Page 18: MVVM Applied: From Silverlight to Windows Phone to Windows 8

© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.