Lessons learned from developing a Windows 8 Metro application in C# Frode Nilsen Nilsen Labs Ticki.

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

Designing, Deploying and Managing Workflow in SharePoint Sites Steve Heaney Product Development Manager OBS
Expression Blend 4 – deep dive
Silverlight is dead! Long live MVVM!
Understanding the MVVM pattern
{ async patterns } - or - using the asynchronous library in the.Net 4.5 Framework for more than keeping your UI responsive.
Async Programming WITH ASYNC TASK
An Introduction To Silverlight Gergely Orosz
Microsoft Focus & Expertise We have a world-class team of Microsoft experts that can make any other platform integrate better with an existing enterprise.
An introduction to. Introductions  I’m Rob Fonseca-Ensor  A Solution Architect at Infusion  I run the Canary Wharf.NET User Group  I blog at
Real world Windows Phone development Igor
Building Silverlight Applications Using the MVVM pattern An Introduction by Peter Messenger Senior Developer – Qmastor
WPF 3rd Party Controls WPF = Windows Presentation Foundation
Joe xamlcoder.com/blog Silverlight / WPF Consultant.
Aptech Borivali(West) Hefin Dsouza. Agenda  What is.NET and What is Visual Studio? .NET Framework 3.5 Overview.  Visual Studio 2008 Enhancements. 
‘Metro’ / Modern – ‘WinRT’ Also known as ‘Windows Store Apps’ --o-0-o-- Windows 8 comes as two parts Win32 and WinRT The Traditional Desktop is Win32 The.
READING, WRITING, BINDING, VALIDATING AND VISUALISING YOUR DATA Business value with Silverlight.
.NET Database Technologies: Introduction to WPF and Entity Framework DataBinding.
V 1.1 Programming III. GUI APIs WPF Hello World Important UI elements UI elements / content models UI elements / inheritance.
Windows Presentation Foundation. Agenda Introduction Developing Applications WPF and WF interoperability Custom Controls Styles and Templates Data Binding.
Reactive Extensions Ye olde introduction and walk-through, with plenty o’ code.
Windows Phone 8 Tips & Tricks for Developers Sascha Corti, Microsoft Switzerland Technical Evangelist | techpreacher.corti.com.
Getting Started with Caliburn.Micro and Windows Phone 7 Gary Ewan Park Twitter: Blog:
Object Oriented Software Development 9. Creating Graphical User Interfaces.
The Microsoft Technical Roadshow 2007 Rich Client Development in XAML Mark Johnston Developer & Platform Group Microsoft Ltd
WHO WILL BENEFIT FROM THIS TALK TOPICS WHAT YOU’LL LEAVE WITH ASP.NET developers, including Web Forms & MVC History of async programming in.NET How async.
Building WPF Line of Business Applications Kiril Matev Senior Technical Evangelist, Infragistics
Windows 8 for Existing.NET Developers Tim Heuer Program Manager Windows Developer Experience Microsoft Corporation.
Nikhil Kothari Software Architect Microsoft Corporation Session Code: WUX312.
Windows 10 UWP MVVM In Depth
Module 4 Taking Control of the User Interface. Module Overview Sharing Logical Resources in an Application Creating Consistent User Interfaces by Using.
Modern Design Principles (MS). Hubs & spoke navigation pattern Hierarchical pattern Best for large collections of related content Content is separated.
User Interface Design In Windows using Blend.
Windows Presentation Foundation ("Avalon"): Beautiful Code, Beautiful Design - Applications Your Designers Can Work With Robert Ingebretsen PRS317 Program.
TAP into async programming
04 |Sharing Code Between Windows 8 and Windows Phone 8 in Visual Studio Ben Riga
Friday, March 8 Creating real Custom Controls Kelvin van Geene 12:15.
Platform abstractionSeparate UI and logic.
An Introduction to Developing Applications for Microsoft Silverlight Jaime Rodriguez
V 1.0 Programming III. XAML Data Binding I.. V 1.0ÓE-NIK, 2014 XAML namespaces Namespaces define the allowed tags and attributes The one without the prefix.
Model View ViewModel Architecture. MVVM Architecture components.
Workflow in Microsoft Office SharePoint Server Jessica Gruber Consultant Microsoft Corporation.
Windows 8 apps and the MVVM pattern SILVERLIGHTSHOW.NET WEBINARS SERIES GILL CLEEREN, October 16 th
© Copyright SELA software & Education Labs Ltd Baruch Hirsch St.Bnei Brak Israel
Programming with MVVM Miguel A. Castro Architect -
Vladimir Milev New Venture Software Sharing Code between WPF and Universal Apps.
THE FUTURE OF C#: GOOD THINGS COME TO THOSE WHO ‘AWAIT’ Joseph Albahari SESSION CODE: DEV411 (c) 2011 Microsoft. All rights reserved.
DES201 - Developers and Designers collaboration Level 200 Aude Mousset Artistic director i-Breed - France Dick Lantim User eXperience Advisor Microsoft.
WPF Course Program, Evaluation, Exams Doncho Minkov Telerik Software Academy academy.telerik.com Senior Technical Trainer
Adam Schultz MVVM and WPF. MVVM Model, View, ViewModel A software architecture designed to separate out User Interface design, Business Logic, and Data.
In Windows 8 Store Applications
Real world Windows Phone development
DotNetSpider Editor Hefin Dsouza
MVVM Made Simple with Prism
It’s a Knockout! MVVM Style Web Development
Build data-driven collection and list apps using XAML
Jim Fawcett CSE775 – Distributed Objects Spring 2011
Creating Windows Store Apps Using Visual Basic
TechEd /9/2018 4:17 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Tech Ed North America /1/ :36 AM Required Slide
Build /2/2019 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
What’s new for Windows 8 Devs Part 2
Build data-driven collection and list apps using ListView in HTML5
Brandon Bray Principal Group Program Manager Microsoft Corporation
XAML Deep Dive for Windows & Windows Phone Apps Jump Start
Enterprise Developer Camp Jumpstart
M3: Printing and PlayTo Jeremy Foster Michael Palermo
Bringing existing managed code into Metro style apps
03 | Async Programming & Networking Intro
An Introduction to the Model-View-ViewModel Pattern
Presentation transcript:

Lessons learned from developing a Windows 8 Metro application in C# Frode Nilsen Nilsen Labs Ticki

Agenda  Async-await done right  Applying the MVVM pattern in Windows 8  Unscientific comparison of MS XAML technologies

The async-await pattern  What it is  What it not is  Pitfalls  Applying it properly

Background  Feb 2012: Introduced in.Net 4.5  Spring 2011: Async CTP  June 2008: Task Parallel Library (TPL,.NET 4.0)

The basics  Two new c# keywords: async and await  Makes asyncronous programming easy  Makes asyncronous code clean

The old way

The new way

1 2

Defintion: Asynchrony  «Not at the same time»  When method returns to the caller  When the caller gets the return value Threads

Going deeper  Async part 1, part 2 NDC 2012 presentation Lucian Wischik (Microsoft Senior Program Manager)part 1part 2  The Task Asynchronous Pattern (TAP) paper by Stephen Toub Feb 2012 (Microsoft Async Guru)Task Asynchronous Pattern  Progress reporting  Cancellation  Retrying  Interleaving  Throttling

The power of asynchronous programming - example

Option 1 – Serially Rq 1Rq 2Rq 3 Time Rq 4

Option 2 – In Parallel Rq 1 Rq 2 Rq 3 Time Rq 4

Request slot 2 Request slot 1 Option 3 – Throttled parallelism Rq 1 Rq 2Rq 3 Rq 4 Time  Google «AsyncSemaphore»AsyncSemaphore

DEMO – the powers of Tasks

Async pitfalls 1 : Blocking threads Task.Wait() Task.Result

Async pitfalls 2 : Deadlocks

Async pitfalls 3 : Exceptions

Async pitfalls 4 : async void

Rule of thumbs for async await  Never return async void from a method, unless it’s a UI event handler  Always await async methods. If you want to run several tasks in parallel, use await Task.WhenAll() or await Task.WhenAny()  Never use Task.Wait() or Task.Result to «synchronify» async methods, except in unit tests.  Never do async calls from constructors

MVVM in Windows 8  Recap of the gist  Applying it to Windows 8  Pitfalls  Tools and tips

MVVM Model View ViewModel Send notifications Data binding and commands Send notifications Updates From MSDN

MVVM Model View ViewModel Send notifications Data binding and commands Send notifications Updates DATABINDING

Things that are impossible to do directly from the ViewModel  Give a visual element focus  Select text in a text box  Scroll an item into view  Show / hide Charms, App-or Navigation-bar

MVVM “MVVM is targeted at modern UI development platforms which support Event-driven programming” Quotes from the Wikipedia article

MVVM “MVVM is targeted at modern UI development platforms which support Event-driven programming” Quotes from the Wikipedia article

DEMO - events

Controls and DataContext A B C A ViewModels Controls B C D E A ListView

Controls and DataContext A B C A ViewModels Controls B C D E A ListView

Controls and DataContext A B C A ViewModels Controls B C D E A ListView D E F

Controls and DataContext A B C A ViewModels Controls B C D E A ListView D E F

Solution: Pub/sub-pattern Messenger Publisher 1 Publisher 2 Subscriber 1 Subscriber 2

Solution: Pub/sub-pattern Messenger Publisher 1 Publisher 2 Subscriber 1 Subscriber 2 User controls ViewModels

Solution: Pub/sub-pattern Messenger Publisher 1 Publisher 2 Subscriber 1 Subscriber 2 MVVM Light Toolkit link

DEMO – pub/sub

MVVM “MVVM was designed to make use of data binding functions in WPF to better facilitate the separation of view layer development from the rest of the pattern by removing virtually all GUI code (“code-behind”) from the view layer” Quotes from the Wikipedia article

Things that are impossible to do directly from the ViewModel  Give a visual element focus  Select text in a text box  Scroll an item into view  Show / hide Charms, App-or Navigation-bar

Things I thought were impossible, but were not  Trigger animations  Achieved through the use of databound visual states and attached propertiesdatabound visual states attached properties  Alter the layout of a grid  You can databind Grid.ColumnDefinition.Width  You can databind visibility of sections within the grid

Windows 8 XAML vs «other XAML»

Example 1: Bundled controls

WinFormSLWin8 ButtonXXX DatePickerXX DataGridXX TreeViewXX ComboBoxXX TabControlXX GridXX StackPanelXX MediaElementXX

Making your own controls  Templates Templates  Visual tree vs Logical tree Visual tree vs Logical tree  Custom dependency properties Custom dependency properties  Custom events

Example 2: Databinding  Binding update on property changed

WinForms

WPF

Silverlight No UpdateSourceTrigger

WinRT No UpdateSourceTrigger No BindingOperations.GetBinding()

WinRT 2 (a slightly better alternative) link

Microsoft XAML technologies  WPF  Silverlight  Windows Phone 7  Windows 8 (WinRT) Time Quality

Thank you  Mail:   Blog:

Q & A