The Windows Runtime (WinRT) is the shared runtime and API space used by store apps across the Windows platform (phone and client) 5 Common WinRT APIs Phone-specific WinRT APIs Windows-specific WinRT APIs Dramatic convergence in 8.1 Goal is 100% convergence for dev scenarios In 8.0, we had ~30% API convergence With 8.1, we move well past 90%+ convergence
HTML Win32 JavaScript Code WinRT C++ CodeC#/VB Code HTMLXAML Windows Runtime XAML WinJS.NET for Windows Store C#/VB Code Silverlight XAML Silverlight.NET Windows Phone Silverlight XAML
Windows Phone 8.1 AppWindows 8.1 App XAML View Phone UI XAML View Windows UI Shared Code, Images, Files WinRT
Windows Phone 8.1 AppWindows 8.1 App XAML View XAML UI XAML View XAML UI Logic Data ? Logic Data
Windows 8.1Windows Phone 8.1 some common APIs may have different behaviour across Windows/Phone Windows Only WinRT e.g. search contract e.g. multiple windows e.g. resizable windows e.g. printing support Phone Only WinRT e.g. action center e.g. status bar e.g. back key handling
files & settings: local, temp, roaming, pickers… network: http, websockets, sockets… notifications: tiles, toasts, badges, push store: app purchases, receipts… sensors: gps, geofencing, gyro, compass… lifecycle: launch, suspend, resume, background tasks localisation: resource resolution from XAML/code…
//Create the picker object FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; // Users expect to have a filtered view of their folders openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".png"); // Open the picker for the user to pick a file StorageFile file = await openPicker.PickSingleFileAsync(); if (file != null) { // Do something with the file... } //Create the picker object FileOpenPicker openPicker = new FileOpenPicker(); // On Windows Phone, setting Filtering to image types // causes Picker to show Camera Roll openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".png"); // Open the picker for the user to pick a file openPicker.PickSingleFileAndContinue();
100% No: Location (Windows) vs. Geopoint (WP) No: Bing Maps (Windows) vs. WinRT Map control (WP)
#if WINDOWS_PHONE_APP Windows.Phone.UI.Input.HardwareButtons.BackPressed += this.HardwareButtons_BackPressed ; #endif
/// /// DataSource.cs /// public partial class DataSource :IDataSource { public async Task > RetrieveFolders(IFolder root) {... // other logic var folders = await LoadFolders(root);... // other logic return folders } /// /// DataSource.WP.cs /// public partial class DataSource { private async Task > LoadFolders(IFolder root) {... }
HERE maps on Windows (8.1)/Phone (8.0)
common, same rendering Button Slider ToggleSwitch ProgressBar etc (many more) common, different content Hub ListView GridView etc. common, different rendering DatePicker TimePicker CommandBar AppBar etc. unique SearchBox Pivot ContentDialog AutoSuggestBox etc.
#if WINDOWS_APP var result = VisualStateManager.GoToState(this, "Windows", false); #elif WINDOWS_PHONE_APP var result = VisualStateManager.GoToState(this, "WindowsPhone", false); #endif
<Application x:Class="FlickrSearch.App" xmlns=" xmlns:x=" xmlns:local="using:FlickrSearch">
<ResourceDictionary xmlns=" xmlns:x=" xmlns:local="using:FlickrSearch"> <ResourceDictionary xmlns=" xmlns:x=" xmlns:local="using:FlickrSearch"> <FlipView ItemsSource="{Binding Items}" ItemTemplate="{StaticResource APhotoTemplate}">
WP 8.1 App – PFN RoamingLocalTemp Windows App – PFN RoamingLocalTemp PFN Roaming folder 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 Windows Notification Service. If app is running when sync occurs, an event is raised. Roaming settings
Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings; // saving settings... roamingSettings.Values["userName"] = someData; // fetching settings... if (roamingSettings.Values.ContainsKey("userName")) { userName = roamingSettings.Values["userName"].ToString(); }
Windows.Storage.ApplicationData.Current.DataChanged += Current_DataChanged;... void Current_DataChanged(ApplicationData sender, object args) { // Refresh your settings... } The event is only fired if the application is active at the time of the change You should still load up all your data when your app starts