230 likes | 486 Views
Required Slide. SESSION CODE: DEV322. Using the MVVM Design Pattern with the Microsoft Visual Studio 2010 XAML Designer. Rockford Lhotka Principal Technology Evangelist Magenic. Nobody’s more serious about Microsoft. . MVVM. View. Properties. Commands. ViewModel. Properties. Methods.
E N D
Required Slide SESSION CODE: DEV322 Using the MVVM Design Pattern with the Microsoft Visual Studio 2010 XAML Designer Rockford Lhotka Principal Technology Evangelist Magenic Nobody’s more serious about Microsoft.
MVVM View Properties Commands ViewModel Properties Methods Model (POCO/DTO/Entity)
MVVM (rich model) View Properties Commands ViewModel Methods/ Properties Model (Rich domain objects)
N-Layer Architecture Interface Interface Control Object Model Data Access Data Storage and Management
Layered Flexibility WPF Silverlight XML Workflow Web IC IC IC IC IC Object Model Data Access Data Access Data Access Data Access Data Access DB2 WCF SQL Oracle XML
Implementing the Layers Interface Patterns Interface Control Object Model Patterns Data Access Patterns Data Storage and Management
Connecting the Parts Drag and Drop View ViewModel Model
Resource Generated in View <UserControl.Resources> <CollectionViewSource x:Key="employeeViewModelViewSource" d:DesignSource= "{d:DesignInstance my:EmployeeViewModel, CreateList=True}" /> </UserControl.Resources>
Code-behind???? private void UserControl_Loaded(object sender, RoutedEventArgs e) { // Do not load your data at design time. // if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)) // { // //Load your data here and assign the result to the CollectionViewSource. // System.Windows.Data.CollectionViewSourcemyCollectionViewSource= // (System.Windows.Data.CollectionViewSource)this.Resources["Resource Key"]; // myCollectionViewSource.Source= your data // } }
Making MVVM Work Shell Data binding & Command router View View Status Errors View factory ViewModel ViewModel ViewModel ViewModel ViewModel (or Presenter)
Summary • MVVM is a good pattern • Avoid code-behind • MVVM requires a little “plumbing” • UI shell abstraction • Route View events to ViewModel verbs • View factory concept
Thank you! Rockford Lhotka rocky@lhotka.net www.lhotka.net Nobody’s more serious about Microsoft.
Required Slide Track PMs will supply the content for this slide, which will be inserted during the final scrub. Track Resources • Visual Studio – http://www.microsoft.com/visualstudio/en-us/ • Soma’s Blog – http://blogs.msdn.com/b/somasegar/ • MSDN Data Developer Center – http://msdn.com/data • ADO.NET Team Blog – http://blogs.msdn.com/adonet • WCF Data Services Team Blog – http://blogs.msdn.com/astoriateam • EF Design Blog – http://blogs.msdn.com/efdesign
Required Slide Resources Learning • Sessions On-Demand & Community • Microsoft Certification & Training Resources www.microsoft.com/teched www.microsoft.com/learning • Resources for IT Professionals • Resources for Developers • http://microsoft.com/technet • http://microsoft.com/msdn
Required Slide Complete an evaluation on CommNet and enter to win!
Sign up for Tech·Ed 2011 and save $500 starting June 8 – June 31st http://northamerica.msteched.com/registration You can also register at the North America 2011 kiosk located at registrationJoin us in Atlanta next year
© 2010 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.