MVVM Applied: From Silverlight to Windows Phone to Windows 8
-
Upload
microsoft-developer-network-msdn-belgium-and-luxembourg -
Category
Technology
-
view
1.993 -
download
0
description
Transcript of MVVM Applied: From Silverlight to Windows Phone to Windows 8
mvvm appliedFrom Silverlight to Windows Phone to Windows 8
LaurentBugnionSenior Director, EuropeIdentityMine
Session Contents• A bit of recapitulation• Code code code
Disclaimer:• I am NOT a Microsoft employee and all opinions
expressed are solely my own.
a brief recap
THE MVVM PATTERN
Interactions: From MVC to MVVM
View
ViewModel
DataBinding CommandsMessages
Model
View Service
Events
PropertyChangedModel View
Controller
The MVC pattern:
Interactions: VM to View, Behaviors
BehaviourBinding
ViewModel View
Interactions: VM to View (Win8)
Binding
ViewModel View
No behaviors in Windows 8 workaround: Use properties and binding PropertyChanged event
PropertyChanged
Interactions: View Services
ViewModel ISelectFilesService
View
injection
INavigationService
injection
actionNavigationService
translating to metro
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
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();}
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
DemoMVVM in Silverlight, Windows Phone, 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)
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!
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
more info athttp://blog.galasoft.ch
http://www.galasoft.ch/mvvm
@LBugnion
Q&A
© 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.