Universal Apps Oct 2014

58
Windows Universal Apps Joe Healy :: @devfish :: [email protected] Blogs.msdn.com/devfish

Transcript of Universal Apps Oct 2014

Windows Universal Apps

Joe Healy :: @devfish :: [email protected]

Blogs.msdn.com/devfish

Universal – Getting Started

• Download VS 2013 Update 3 or VS2014 previews

• Make sure physical phone is at Windows Phone 8.1 or later

• Make sure Windows is at 8.1 or later

Universal App Templates

• Blank• Pretty straight forward

• Hub • Similar to grid template in

Windows 8

• Displayed as pivot control in Windows Phone

File, New, Universal AppDEMO

Universal Apps Project Layout

Windows 8.1 XAML Project

Windows Phone 8.1 XAML Project

Shared Project linked backInto other projects

Common reference itemsNOT pcode lib

Unified Windows Apps

• Develop W8 and WP8 app with Universal Apps• Choose to let user download an app once, and get it on both platforms

• Free or paid

• New Unified Windows Apps symbol

Shared Project

• Simplify sharing files across platform specific projects

• Not meant to be compiled on their own

• Not meant to be compiled directly to reference libraries

• Allows you to include selected files into WP81 and Win81 projects separately, but in a single place

• Some things just can’t go in a PCL, aka APP.XAML and #ifdef

PortableClass Libraries

I compile just onceand know it works

on all platforms

SharedProjects

I can easily include platform-specific code under #if or partial classes

Debug Target

• Dropdown menu to choose debug target• Switch between targeting Windows 8 and Windows Phone

• Run both in emulators or on a device

Shared Project Context Switcher

• Changes how screen is rendered

• Changes what shows up in the device tab

Shared Project Context Switcher

Shared Project Context Switcher

Shared Project Context Switcher

• ErrorChecks APIs for each platform

#ifdef directive

• constants WINDOWS_APP and WINDOWS_PHONE_APP are conveniently predefined for you

• Have platform specific code for each• If windows app, do this

• If windows phone app, do this

#ifdef directive#if WINDOWS_APP

if (!rootFrame.Navigate(typeof(HubPage)))#endif#if WINDOWS_PHONE_APP

if (!rootFrame.Navigate(typeof(WindowsPhoneStartPage)))#endif

{throw new Exception("Failed to create initial page");

}

Classes Structs Interfaces

Windows 8.1 SDK 566 119 59

Windows Phone 8.1 SDK 624 131 57

+58 +12 -2

Windows.UI.Xaml.*

* Via Tim Heuer’s analysis runs at BUILD 2014

Visual Studio streamlines developing universal Windows apps

You can tailor the design to each device

• Layout: Panel, StackPanel, Grid, Border• Buttons, Slider, ToggleSwitch, CheckBox, RadioButton,

ProgressBar• TextBox/TextBlock• Shapes/Path

‘Primitives’ – Same Across Platforms

HubCommandBarDate/Time Pickers and List PickersListViewFlyoutsMediaAds SDK

‘Primitives’ – same API, tailored behavior

Windows• AppBar• SearchBox• SettingsFlyout

Windows Phone• Pivot• AutoSuggestBox• ContentDialog• Maps• System Chrome

Device-specific APIs

what’s it really mean?converged controls

80% exact same XAML 20% custom

Common SignatureOptimized

DatePicker

TimePicker

CommandBar

Button

CheckBox

RadioButton ProgressBar

Slider

ToggleSwitchHub

Pivot

ListView

GridView

AppBar

SysTray

Why Custom

Windows Windows Phone

<Page.BottomAppBar>

<CommandBar>

<AppBarButton Icon="Accept" Label="Accept" />

<AppBarButton Icon="Cancel" Label="Cancel" />

<CommandBar.SecondaryCommands>

<AppBarButton x:Uid="AboutAppBarButton" Icon="Help" />

<AppBarButton x:Uid="HomeAppBarButton" Icon="Home" />

</CommandBar.SecondaryCommands>

</CommandBar>

</Page.BottomAppBar>

CommandBar

CONTROLS PLAYDEMO

Navigation APIs SamePhone Hardware Back ButtonWindows in-app Back Button

Navigation Model

#if WINDOWS_PHONE_APPWindows.Phone.UI.Input.HardwareButtons.BackPressed +=

HardwareButtons_BackPressed;#endif

ApproachesNative App( aka 8.0 )

SL 8.1 (WP) Windows Store API ( aka Universal )

• Continues to work as isAdd new funct and fixes

• Reuse most codeAdd 8.1 features ( geofence, calendar, screen recording, WNS, others )

• Same app model and UI• Easy to support

Not much work Repackage and republish Umm. To port? Just a little bit. Plus more.

Runs on 8.0 and 8.1 WPRuns on 8.0 and 8.1 Win8

WP 8.1Not all phones at 8.1 yet

WP 8.1Win 8.1

No future enhancements

Controls, some older libs not there

Win10 future? Win10 Future? Pathway to Win10

App Studio

• File New Project for Universal Apps

• Why not?

• http://appstudio.windows.com

Controls

• XAML and Phone Toolkit no worky here

• Not much good stuff open source

App StudioDEMO

Telerik

• Universal Controls in Beta - http://www.telerik.com/windows-universal-ui - release around Nov 1 – not sure of price

Telerik Controls

• AutoComplete

• BusyIndicator

• Chart

• Date Picker

• Time Zpicker

• Rating

• DataBoundList

Telerik BetaDEMO

Sync Fusion

• Sync Fusion - $1 for individual developer –http://www.syncfusion.com/sales/offers/winrt-hobbyist - $399 to companies

• In release NOW

SyncFusion

• Grid

• DocIO / XlsIO / PDF

• Busy Indicator

• Hub Tile

• Chart

• Range Navigator

• Guages

• Maps

• Treemap

• Barcode

• Sparkline

• Calculate

• TextBoxExt

• ComboBox

• DropDown

• Date and Time Picker

• Numeric Updown

… lots more

SyncFusion

Sync FusionDEMO

To Share or Not to Share

• Question…How much of your UI code will be shared?• Options

• Completely separate pages

• Shared page with separate styles and templates

• Shared page with shared styles and templates

• Some other combination

• Answer…whatever fits your app the best!

Shared Styles/Templates

• How to share styles/templates• Add styles and templates to Shared Project

• Share app.xaml• Reference styles and templates in ResourceDictionary

SHARED STYLE/TEMPLATESUNIVERSAL TIP

Storage

Most file content is managed with these types• Local files/folders• File activation• Media libraries• Share contract• Pickers

Nearly all Windows Runtime APIs are supported

StorageFile and StorageFolder

IsolatedStorage

Folder

App Data Model

Roaming

Folder Settings

• Data roamed across Windows devices

Local

Folder Settings

• Primary local store

Temp

Folder

• Temporary storage• Cleaned up in low

storage condition

LocalCache

Folder

• Not backed up• Not cleaned up• Phone only

User data exposed via KnownFolders• RemovableDevices (SD)• MusicLibrary• PicturesLibrary• VideosLibrary

Direct access protected by capabilityAll public files are available via pickers

Accessing User Content

•Used to maintain access to shared files/folders• File activation• Share contract• File picker

•Knowledge of file is maintained across deletes•If you need the file, make a copy

Access Cache

ROAMING

Phone App – PFN 12345

Roaming Local Temp

Windows App – PFN 12345

RoamingLocalTemp

PFN 12345

Roaming

App writes data using standard file/settings APIs.

Sync engine transfers data periodically based on triggers (user idle, battery, network, etc.)

OneDrive stores up to 100kb of roaming data per app (not included in user quota). If app exceeds the limit, sync stops.

Other clients are notified of updated data via WNS. If app is running when sync occurs, an event is raised.

ROAMING

LocalCache

Use roaming for settings and small stateStick to core WinRT typesAvoid dependencies across files/settingsBe resilient against sync delaysUse Windows.Security.Credentials for secure data

Roaming Best Practices

ROAMINGDEMO

NUGET PACKAGES

• Must be added to both Windows and Windows Phone projects if referenced in shared folder

• “if your Windows Store app contained an assembly reference for a third-party library, and you move the associated code into the Shared folder, then you also have to reference the third-party library in the Windows Phone project”

Linked Apps

• Share IAP and “Paid” status

• Buy once, own everywhere

• Shared roaming

• Shared credential vault

• Uses common Product Family Number (PFN)

• Linking to WP8, WinRt possible

Linked Apps

Visual Studio 2014 – WinJS Universal Apps

Resources

• dfWiki Universal Apps -http://dfwiki.devfish.net/technology.Universal-Apps.ashx

• Developing Apps Using the Common XAML UI Framework -http://channel9.msdn.com/Events/Build/2014/2-507

• What About XAML UI and Controls? Shawn Oster - 2-516 -http://channel9.msdn.com/Events/Build/2014/2-516

• Using VS to Build XAML Converged Apps – Nivit Saxena -http://channel9.msdn.com/Events/Build/2014/3-591

Thanks

[email protected]

Todo

• Universal app samples out of windows 8.1 sdk