Developing on Windows 8

42

description

A presentation on Windows 8 development I gave at NNUG Vestfold the 26th of September 2012

Transcript of Developing on Windows 8

Page 1: Developing on Windows 8
Page 2: Developing on Windows 8

Developing on Windows 8

Power point template by Colin Eberhardt

Page 3: Developing on Windows 8

Agenda

WinRT Platform Basics

Best practices

Pickers

Contracts

Tiles

Notifications

Page 4: Developing on Windows 8

Who am I

Einar Ingebrigtsen

[email protected]@einari

http://blog.dolittle.comhttp://www.ingebrigtsen.info

Page 5: Developing on Windows 8

The target

One runtime to rule them all

Page 6: Developing on Windows 8

Old school interop

Your Managed Code

Traditional Windows API

Manually Generated Interop Code

Page 7: Developing on Windows 8

Windows RT style

Your Managed Code Windows 8 API

Windows Runtime

Page 8: Developing on Windows 8

Architecture

Metro style appLanguage Support

(CLR, WinJS, CRT)

Language Projection

Windows Metadata & Namespace

Web Host (HTML, CSS, JavaScript)

Windows Core

Runtime Broker Windows Runtime Core

UI Pickers Controls Media

XAML Storage Network …

Page 9: Developing on Windows 8

Bridging the gap

FileOpenPicker picker = new FileOpenPicker();picker.FileTypeFilter.Add("*")a;

StorageFile file = await picker.PickSingleFileAsync();

Windows.Storage.Streams.IInputStream inputStream = await file.OpenReadAsync();

System.IO.Stream stream = inputStream.AsStreamForRead();System.IO.StreamReader reader = new StreamReader(stream);

string contents = reader.ReadToEnd();

Page 10: Developing on Windows 8

Missing things

Reflection API changedType details through GetTypeInfo() – extension methodEmit namespace practically empty - security

Page 11: Developing on Windows 8

XAML

Originally developed for Windows Vista and exposed as WPF

Defines what you see

Layout is by default not flowing, as in HTML

Can observe changes (Active View)

Page 12: Developing on Windows 8

Tools

Visual Studio 2012

Blend for VS2012

Page 13: Developing on Windows 8

Binding

SourceDefaults to DataContextCan use StaticResource as source

ModeOneWay, TwoWay, OneTime – OneWay default

ValidationValidatesOnExceptionValidatesOnNotifyDataErrors

INotifyDataErrorInfo

Page 14: Developing on Windows 8

Binding

StringFormatStringFormat = ‘MMM.dd.yyyy’

Null and Fallback valuesTargetNullValue=‘(None)’FallbackValue=‘(Data Context Not Set)’

IValueConverter

Page 15: Developing on Windows 8

Element to Element

Can bind directly to other elements properties

Binds by name of element

Page 16: Developing on Windows 8

Events

You still have events as before – buttons can be clicked and raise an event

RoutedEvents – bubbles through the UI

Page 17: Developing on Windows 8

Async

var future = DownloadDataAsync(...); future.ContinueWith(data => ProcessData(data));

DownloadDataAsync

ProcessData

STOP

ProcessDataDownloadData

var data = DownloadData(...);ProcessData(data);

Page 18: Developing on Windows 8

Async Models

Windows Runtime : IAsyncOperation<T>

.NET Framework : Task<T>

C# 5.0 – async / await

Page 19: Developing on Windows 8

Async – C# style

Marked with “async” modifier

Must return void or Task<T>

Use “await” operator to cooperatively yield control – remember to mark with “async”

Feels just like good old synchronous code

Page 20: Developing on Windows 8

Patterns & Practices

MVVMInspired by PresentationModel by Martin FowlerGood for decoupling – promotes testability

Compositioning

Commands

Actions / Triggers / Behaviors

Page 21: Developing on Windows 8

MVVM

Model

ViewModel

View

Observes

Observable

Page 22: Developing on Windows 8

Compositional UIs

HeaderN

avig

ati

on

Main Content

Footer

Page 23: Developing on Windows 8

Event Aggregator

ViewModel 1 ViewModel 2

Aggregator

Page 24: Developing on Windows 8

Tiles

Tap on tile to launch or switch to an app

Static default tile specified in app manifest

Two sizes:

Both sizes can have live updates

Page 25: Developing on Windows 8

Live Tiles

Tiles updates using pre-defined templates

Templates provide rich rendering options

Text-only image-only or combination

JPEG or PNG only, max size 150 KB

Optional “peek” animation

Local or cloud updates

Page 26: Developing on Windows 8

Notification Queuing

Opt-in to automatically cycle tile through last five notifications

By default only last notification shown

Page 27: Developing on Windows 8

Secondary Tiles

Tiles created by “pinning” content from app

Pin initiated by app via simple runtime call

User confirms pin operation via system UI

Exposes a personalized surface for app

Same capabilities as app tiles

Launch leads to relevant content

Page 28: Developing on Windows 8

Windows Notification Service

Enables delivery of tile and toast notification over the internet

Tile updates and notifications shown to the user even if your app is not running

WNS handles communication with your app

Scales to millions of users

WNS is a free service for your app to use

Page 29: Developing on Windows 8

Push Notification Overview

Windows 8 Cloud Service

Windows Push Notification

Service

Metro Style App

Notification

Client Platform

2

3

1 3

1. Request Channel URI

2. Register with your Cloud Service

3. Authenticate & Push Notification

Page 30: Developing on Windows 8

Toast Notifications

Toast notifications deliver transient messages outside the context of the app

Use toast notifications to get user’s attention immediately

User is in control and can permanently turn off toast notifications from your app

Allows quick navigation to a contextually relevant location in your app

Toast notifications are easy to invoke from your app or from the cloud

Page 31: Developing on Windows 8

Toast Templates

Uses same template architecture as Live Tiles

Rich set of rendering options available

Page 32: Developing on Windows 8

Contracts

Contracts enable integrating the Windows 8 experience into your app

Yields a consistent UI for all apps

Page 33: Developing on Windows 8

Search

Enables your app to interact and respond to

SuggestionsSearch Query

Page 34: Developing on Windows 8

Settings

Consistently given one place to get searchContext sensitive to the front facing app

Page 35: Developing on Windows 8

Share

Your app can share anything (text, images, binaries)Automatically filters available applications to share to

Your app can be a share target – receive sharing from othersAdd sharing target as a capability and you can receive share requests

Page 36: Developing on Windows 8

Play To

Ability to stream media to compatible devices

Page 37: Developing on Windows 8
Page 38: Developing on Windows 8

Summarized

Windows RT is a huge leap, both in faith but also technically

Consistent API that feels mature from day one

Well architected solutions putting the user first

Makes us as developers focus on adding the business value

Page 40: Developing on Windows 8

Resources

MVVM Lighthttp://mvvmlight.codeplex.com/

Setting up push notifications – registering your apphttps://manage.dev.live.com/build

WAT for Windows 8 + WnsRecipehttp://watwindows8.codeplex.com/releases/view/73334

Calisto – UI Framework for WinRThttps://github.com/timheuer/callisto

Get into the store – register as a deveveloperhttp://msdn.microsoft.com/en-us/windows/apps/

Page 41: Developing on Windows 8

Thanks for your attention

Page 42: Developing on Windows 8