Windows 10 UWP MVVM In Depth

Slides:



Advertisements
Similar presentations
Module 1: Creating an Application by Using Windows Presentation Foundation Overview of WPF Creating a Simple WPF Application Handling Events and Commands.
Advertisements

Expression Blend 4 – deep dive
Chapter 13 Review Questions
An Introduction to the Model-View-ViewModel Pattern Srsly? Another MV* Pattern? Srsly? Another MV* Pattern?
Essentials of Developing Windows Phone Apps Chinthaka Dissanayake Tech Lead Exilesoft.
Microsoft Focus & Expertise We have a world-class team of Microsoft experts that can make any other platform integrate better with an existing enterprise.
Real world Windows Phone development Igor
Building Silverlight Applications Using the MVVM pattern An Introduction by Peter Messenger Senior Developer – Qmastor
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg.
Windows.Net Programming Series Preview. Course Schedule CourseDate Microsoft.Net Fundamentals 01/13/2014 Microsoft Windows/Web Fundamentals 01/20/2014.
Creating Business Workflow Using SharePoint Designer 2007 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft SQL Server.
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
Developing Mobile Applications using MVVM with Xamarin Forms
.NET Database Technologies: Introduction to WPF and Entity Framework DataBinding.
Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.
Microsoft SharePoint Server 2010 for the Microsoft ASP.NET Developer Yaroslav Pentsarskyy
Alcatel-Lucent CDC Workshop, Coaching & Knowledge Transfer Architecture.
Windows Phone MVVM and Unit Testing Step by Step Andy Wigley Windows Phone Development MVP, Mobile Software Consultant APPA Mundi Ltd WPH208.
Core Indigo Patterns Ted Neward
Windows Store apps… lots of choices Windows Store Apps Communication & Data Application Model Devices & Printing WinRT APIs Graphics & Media JavaScript.
JAVASCRIPT WITH A VIEW Jordan Knight Solution Architect Xamling SESSION CODE: WEB305 (c) 2011 Microsoft. All rights reserved.
Nikhil Kothari Software Architect Microsoft Corporation Session Code: WUX312.
Securing Angular Apps Brian Noyes
Getting Started with Aurelia
04 |Sharing Code Between Windows 8 and Windows Phone 8 in Visual Studio Ben Riga
V 1.0 Programming III. Automatic notifications with data binding (…Changed, INofityPropertyChanged, ObservableCollection, DataTemplate) Data formatters.
Model View ViewModel Architecture. MVVM Architecture components.
Solliance ( CTO Microsoft Regional Director Microsoft MVP Pluralsight author t e
Windows 8 apps and the MVVM pattern SILVERLIGHTSHOW.NET WEBINARS SERIES GILL CLEEREN, October 16 th
Spaso Lazarević Microsoft MVP Nova banka ad Banja Luka Building business application using Visual Studio 2013 LightSwitch.
Programming with MVVM Miguel A. Castro Architect -
© Copyright SELA software & Education Labs Ltd Baruch Hirsch St.Bnei Brak Israel
/DEV/TM #1 Building Cross-Platform Apps with Xamarin and MvvmCross Flavius-Radu DEMIAN.
Part of the Microsoft.NET Framework 3.0 Tomer Shamam.NET Technologies Expert Sela Group
The cutting edge event for ITPros and Devs December 7-8, 2013 Athens, Greece Fix it once use it everywhere Elias Markelis MCT, Windows Phone Enthusiast.
Build Hybrid Mobile Apps with Ionic, Angular, & Cordova Brian
Solliance ( CTO and Co-founder Microsoft Regional Director Microsoft MVP Pluralsight author
Adam Schultz MVVM and WPF. MVVM Model, View, ViewModel A software architecture designed to separate out User Interface design, Business Logic, and Data.
12/29/2017 2:33 PM © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN.
In Windows 8 Store Applications
Real world Windows Phone development
Office Add-ins: Make your solution a native part of Office
The Universal Windows Platform
Building Custom Workflows
Ben Riga 02 | Basics of View Models Ben Riga
TechEd /26/2018 3:42 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Build Windows 10 UWP MVVM Apps with Prism
Building Web Applications with Microsoft ASP
It’s a Knockout! MVVM Style Web Development
Office Power Hour New developer APIs and features for Apps for Office
Miguel A. Castro Architect IDesign
Introduction to the MVVM Pattern
11/19/2018 © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks.
Integrating Security Roles into Microsoft Silverlight Applications
Modern web applications
An introduction to MVVM using WPF NISCHAL S
Rich single page applications with SharePoint
Tech Ed North America /1/2018 4:27 PM Required Slide
Sessions about to start – Get your rig on!
1/2/2019 9:19 AM © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS.
1/10/2019 © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks.
Modern web applications
What’s new for Windows 8 Devs Part 2
Microsoft Office 4/3/2019 Deep Dive into native Universal App development with the Office 365 APIs Speaker name Title Microsoft Corporation © 2012 Microsoft.
TechEd /4/2019 3:19 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Using tiles and notifications
XAML Deep Dive for Windows & Windows Phone Apps Jump Start
Bringing existing managed code into Metro style apps
Tech Ed North America /6/2019 2:07 PM Required Slide
An Introduction to the Model-View-ViewModel Pattern
Presentation transcript:

Windows 10 UWP MVVM In Depth Brian Noyes CTO & Co-founder, Solliance Inc (www.solliance.net) brian.noyes@solliance.net, @briannoyes

Visual Studio Connections About Brian Noyes CTO and Co-founder, Solliance www.solliance.net Microsoft Regional Director Microsoft MVP Pluralsight author www.pluralsight.com Web API Insider, Windows Azure Insider, Window Store App Insider, C#/VB Insider t e brian.noyes@solliance.net @briannoyes http://briannoyes.net Updates will be available at http://www.devconnections.com/updates/LasVegas_Fall08/VS

Agenda Windows 10 UWP Big Picture MVVM Pattern Fundamentals MVVM Construction Approaches MVVM Communications Integrating MVVM with Windows 10 UWP Platform Features Leveraging MVVM Frameworks

Windows 10 Universal Windows Platform Native APIs of Windows 10 Core APIs common across all Windows 10 platforms Device-Family extensions for desktop, mobile, IoT Derivative from Windows 8 “Windows Runtime” Less prescriptive/constraining than Windows Runtime was Styling Windowing Background tasks App activation

Windows 10 UWP MVVM Not “baked” into the platform at all Same core capabilities exist to use MVVM in UWP XAML apps as other XAML platforms: DataContext Rich two way data binding Property change notifications DataTemplates

Windows 10 UWP MVVM Need to be able to leverage platform specific capabilities and limitations when using MVVM in UWP Frame-based navigation App activation / lifecycle schemes Transient state management Compiled bindings Lack of Implicit DataTemplates

UI Separation Patterns Goals Architectural goals Loose coupling Separation of concerns Leads to Maintainability Testability Extensibility Putting all your logic here is not good enough

No Separation of Concerns private void ComputeCustomerOrdersTotal(object sender, RoutedEventArgs e) {     var selectedCustomer = this.customerDataGrid.SelectedItem as Customer;     var orders = (from order in dbContext.Orders.Include("OrderItems")                     where order.CustomerId == selectedCustomer.Id                     select order);     var sum = 0;     foreach (var order in orders)     {         foreach (var item in order.OrderItems)         {             sum += item.UnitPrice * item.Quantity;         }     }     this.customerOrderTotal.Text = sum.ToString(); } UI Element Access Data Access Interaction/Business Logic

Good Separation of Concerns Business Logic Data Access Model Entities Shared Client Logic View Interaction Logic UI Element Access

MVVM Responsibilities View Data Binding ViewModel Model Model Object Model Object Model Object Client Services / Repositories

Model Responsibilities Contain the client data Expose relationships between model objects Computed properties Raise change notifications INotifyPropertyChanged.PropertyChanged Validation INotifyDataErrorInfo/IDataErrorInfo

View Responsibilities Structural definition of what the user sees on the screen GOAL: “No Code Behind” Reality: Sometimes need some code behind

ViewModel Responsibilities Expose data to the view for presentation and manipulation Encapsulate interaction logic Calls to business/data layer/service Navigation logic State transformation logic

ViewModel Data Model ViewModel OrderItem Customer “Expose” public Customer Customer { get; set; } 1 * public bool ShowCustomerAlert { get; set; } Order “Wrapped” public ObservableCollection<OrderItem> Orders { get; set; } 1 * Client State public bool LoggedIn { get; set; } Order_Detail * 1 OrderItem Product OrderDate Quantity ProductName Authentication Service

Client Services / Repositories Shared functionality or data access Consumed by one or more ViewModels Decouples ViewModels from external dependencies Data storage Service access Client environment Can act as data caching container

MVVM Construction / “Marrying” Schemes Fundamental equation of MVVM: View.DataContext = ViewModel] Approaches: View-First XAML construction View-First Code behind construction View-First ViewModelLocator construction ViewModel-First DataTemplate construction

View-First - XAML InitializeComponent() <UserControl x:Class="ZzaDashboard.Customers.CustomerEditView“ Width="400“ Loaded="OnLoaded" ...> <UserControl.DataContext> <local:CustomerEditViewModel /> </UserControl.DataContext> ... </UserControl>

View-First Code-Behind public partial class CustomerListView : UserControl { public CustomerListView() this.DataContext = new CustomerListViewModel(); InitializeComponent(); }

View-First - ViewModelLocator ViewModelLocator is a meta- pattern for automatically locating and hooking up the right ViewModel

ViewModelLocator Process What view is being constructed? What ViewModel should I construct? Construct (and DI) ViewModel Set ViewModel as View DataContext

Data Binding DataContext <UserControl x:Class="..." ...> <Grid> ... <Label Content="First Name:" ... /> <TextBox ... Text="{Binding Customer.FirstName}"/> <Label Content="Last Name:" ... /> <TextBox ... Text="{Binding Customer.LastName}" /> <Button ... Command="{Binding SaveCommand}" /> </Grid> </UserControl> public class CustomerEditViewModel : INotifyPropertyChanged { public Customer Customer ... }   public ICommand SaveCommand { get; set; }

ViewModel-First with Implicit DataTemplates CustomersOrderTreeViewModel <ContentControl Content="{Binding CurrentViewModel}" /> <DataTemplate DataType="{x:Type local:CustomersOrderTreeViewModel}"> <local:CustomersOrderTreeView /> </DataTemplate>

MVVM Communications ViewModel => View : Data binding + property change notifications View => ViewModel : Commands ViewModel = > ViewModel : Pub/Sub messaging

Commands Based on classic Command design pattern Invoker – View control Receiver - ViewModel Use delegating command implementation Supports decoupled command handling invocation Supports enabling/disabling associated control Invoker ICommand Delegate Command Receiver

Hierarchical MVVM / Navigation Page Root View Root ViewModel List View Details View Item ViewModel Item View Item ViewModel Item View List ViewModel Details ViewModel

MVVM and UWP Navigation Page Page ViewModel ViewModel INavigationService FrameNavigationService Frame

Application Lifecycle Management UWP application lifecycle states: Not Running Running Suspended ClosedByUser Terminated Not Running Launch Running Launch Launch Switch Back Switch Apps Terminated Suspended ClosedByUser Low Memory Shutdown

UWP MVVM Frameworks Prism 6 Template10 MVVM Light Caliburn MVVMCross

Prism 6 for UWP Contents Prism.Core Prism.Windows MVVM Support Commands PubSubEvents Prism.Windows Navigation Application State management Validation

Please use Event Board to fill out a session evaluation. Questions? Please use Event Board to fill out a session evaluation. Thank you!