Windows 10 is finally here. Now is the time to learn about the awesome new features that the platform offers. Do you want to know what Windows 10 enables for developers? Or do you want to see how you can enhance your existing Windows 8.1 app? In this session, we will give you a full overview of the most important new features of Windows 10.
4. http://windows.Microsoft.com
Agenda
• The Story of 10
• XAML: then and now
• Data binding improvements
• Adaptive, adaptive and more adaptive
• New in Live Tiles
• The App Lifecycle
• (Optional) App-to-App communication
• (Optional) App Services
6. http://windows.Microsoft.com
Windows Core
The refactored common core
One hardware platform
Universal hardware driver
Standard network and I/O
Phone
Device
Xbox
Device
Desktop
Device
Windows Core
Desktop
SKU
Phone
SKU
Xbox
SKU
13. http://windows.Microsoft.com
Windows app
A single binary
Running on any device
Testing for capabilities
Adjusting to devices
Phone
Device
Xbox
Device
Desktop
Device
Windows Core
Universal Windows Platform
Windows App
14. http://windows.Microsoft.com
The developer story
When writing for iOS,
A developer writes for iPad & iPhone
When writing for Android,
A developer writes for all supported devices
When writing for Windows 8,
A developer writes for each devices
When writing for Windows 10,
A developer writes for every device
19. http://windows.Microsoft.com
Test capabilities at runtime
Use Adaptive Code to light-up
your app on specific devices
var api = "Windows.Phone.UI.Input.HardwareButtons";
if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent(api))
{
Windows.Phone.UI.Input.HardwareButtons.CameraPressed
+= CameraButtonPressed;
}
23. http://windows.Microsoft.com
RelativePanel
Defines an area within which you can position and align child objects in relation to
each other or the parent panel.
RelativePanel is a constraint based layout container that you can use to create UIs
by expressing spatial relationships between elements.
Using RelativePanel’s attached properties, you can position a UI element relative to
another UI element (A is RelativePanel.Below B) as well as relative to the panel (A is
RelativePanel.AlignTopWithPanel).
-MSDN
61. http://windows.Microsoft.com
x:Bind
Compiled binding
Bindings are committed at compile-time
Strongly-typed binding
Duck binding is not supported
Default mode is OneTime
OneWay and TwoWay are still available
Standard binding approaches
INotifyPropertyChanged, IObservableVector, INotifyCollectionChanged
69. http://windows.Microsoft.com
Binding for Events
<Button Click="PokeEmployee">Poke Employee</Button>
<Button Click="{x:Bind Employee.Poke}">Poke Employee</Button>
Signature
Have no parameters - void Poke()
Match event parameters - void Poke(object sender, RoutedEventArgs e)
Match event base types - void Poke(object sender, object e)
Overloading is not supported
Because all events are eligible:
This may replace ICommand & EventToCommand
Note: this does not include parameter or CanExecute
70. http://windows.Microsoft.com
Page.ViewModel
public sealed partial class MainPage : Page
{
public MainPage()
{
InitializeComponent();
this.DataContextChanged += (s, e) =>
{
ViewModel = DataContext as ViewModels.MainPageViewModel;
};
}
// strongly-typed view models enable x:bind
public ViewModels.MainPageViewModel ViewModel { get; set; }
}
72. http://windows.Microsoft.com
When to use classic binding
Duck Typing
Text=“{Binding Age}” works for both PersonModel & WineModel
Dictionary graphs
Use {Binding} with JSON or other untyped objects
Code-behind binding: adding and removing
bindings on the fly
Can add/remove {x:Bind} @ runtime
Use in a style
{x:Bind} can’t be used in a style for setters
{x:Bind} can be used in a DataTemplate that is defined in the style
73. {x:Bind} is not for
every situation right now.
It will in the future.
74. x:Bind can meet your binding
needs most of the time.
Let’s say around 80%
79. http://windows.Microsoft.com
Tailored design
Build pages/code for individual families
Use MRT in App.xaml.cs to determine the family
One-handed interface?
Typically phone or small tablets
Test diagonal screen size (<7")
if (physical_diagonal_size <= 7)
// optimized for one-handed operation
rootFrame.Navigate(typeof(MainPage_OneHanded), e.Arguments);
else
rootFrame.Navigate(typeof(MainPage), e.Arguments);
89. http://windows.Microsoft.com
Three core adaptive approaches
Responsive design
Resize your content
Reflow your content
Adaptive design
Reposition your content
Redesign your content
Tailored design
96. http://windows.Microsoft.com
Using Specific Versions of an API
Adaptive code techniques are not only for handling
device family-specific code
You write your app against a base UWP version, but 6
months later, UWP v.Next ships to users machines
Applies to Extension SDKs and Packages as well – new versions may offer new functionality
You want to keep supporting customers who haven’t
updated yet, but take advantage of up-level APIs for those
who have
98. http://windows.Microsoft.com
Gate use of up-level APIs
var contract = "Devices.Scanners.ScannerDeviceContract";
int majorVersionRequired = 3;
if (Windows.Foundation.Metadata.ApiInformation.
IsApiContractPresent(contract, majorVersionRequired ))
{
// Call the API that is present in V3 and above
...
}
else
{
// Your original code supporting users who haven’t upgraded yet
...
}
100. http://windows.Microsoft.com
What about shared projects?
Shared Projects share code
at the code level, pre-
compilation
Share with Windows 8.1 projects, Xamarin projects,
anything…
Still completely supported
#if Compilation directives used to conditionally include
code by those projects referencing the Shared Project
1. WINDOWS_APP
2. WINDOWS_PHONE_APP
3. WINDOWS_UAP (new)
101. http://windows.Microsoft.com
Use Adaptive Code in Shared too!
#if WINDOWS_PHONE_APP
// Processing for Windows Phone 8.1 only
Windows.Phone.UI.Input.HardwareButtons.CameraPressed
+= this.Camera_Pressed;
#elif WINDOWS_UAP
// Processing for Windows UWP – Desktop AND Mobile
if (Windows.Foundation.Metadata.ApiInformation
.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons";))
{
// But this is only for UWP AND Mobile
Windows.Phone.UI.Input.HardwareButtons.CameraPressed
+= this.Camera_Pressed;
}
#endif
103. http://windows.Microsoft.com
Basic State
Plate
App Logo
Short Name
Plate
App Logo
Short Name
Semi-Live State
Plate
App Logo
Short Name
Badge
Plate
App Logo
Short Name
Badge
Live State
Plate
App Icon
Short Name
Badge
Content
Plate
Short Name
Badge
App Icon
Content
Tile anatomy
105. http://windows.Microsoft.com
Update tile badge
// build badge
var type = BadgeTemplateType.BadgeNumber;
var xml = BadgeUpdateManager.GetTemplateContent(type);
// update element
var elements = xml.GetElementsByTagName("badge");
var element = elements[0] as Windows.Data.Xml.Dom.XmlElement;
element.SetAttribute("value", "47");
// send to lock screen
var updator = BadgeUpdateManager.CreateBadgeUpdaterForApplication();
var notification = new BadgeNotification(xml);
updator.Update(notification);
106. http://windows.Microsoft.com
Responsive tiles
Tiles are not
always the same size
Tiles adapt to
the screen they are on
Since the Start grid has different densities
and adapts to the screen size of your device,
so do our tiles and the content within them.
High density exampleLow density example
109. http://windows.Microsoft.com
Legacy templates
If a template meets your
needs, go ahead and use it.
Previous templates remain
Phone and Windows templates have been merged
There are over 80 templates available
110. http://windows.Microsoft.com
Create a secondary tile
var tileId = "DetailsTile";
var pinned = SecondaryTile.Exists(tileId);
if (!pinned)
{
var tile = new SecondaryTile(tileId)
{
DisplayName = "Record details",
Arguments = "123"
};
// extra details
var success = await tile.RequestCreateAsync();
}
132. http://windows.Microsoft.com
Extended execution
Requesting extended execution
There is no guarantee resources are available
Extended execution has no UI
Scenario “I have data this time”
Handle the Revoked event (1 second warning)
Scenario “I’m a special kind of app”
These apps run indefinitely
Special kinds of apps
1. Turn-by-turn (location tracking) app
2. Audio & VOIP application
133. There is a balance between load
speed & shutdown time
148. http://windows.Microsoft.com
URI Activation++
Invoke a specific app
var options = new LauncherOptions();
options.TargetApplicationPackageFamilyName = "24919.InstapaperIt";
var launchUri = new Uri("instapaper:?AddUrl=http%3A%2F%2Fbing.com");
await Launcher.LaunchUriAsync(launchUri, options);
149. http://windows.Microsoft.com
URI Activation++
Send Files
var options = new LauncherOptions();
options.TargetApplicationPackageFamilyName = "24919.InstapaperIt";
var token = SharedStorageAccessManager.AddFile (gpxFile);
ValueSet inputData = new ValueSet();
inputData.Add("Token", token);
var launchUri = new Uri("instapaper:?AddUrl=http%3A%2F%2Fbing.com");
await Launcher.LaunchUriAsync(launchUri, options, inputData);
150. http://windows.Microsoft.com
Query URI Support
Discover if app already installed to handle a Uri
var queryUri = new Uri("instapaper:");
await Launcher.QueryUriSupportAsync(queryUri, LaunchUriType.LaunchUri);
?
var queryUri = new Uri("instapaper:");
string packageFamilyName = "24919.InstapaperIt";
await Launcher.QueryUriSupportAsync(queryUri, LaunchUriType.LaunchUriForResults, packageFamilyName);
152. http://windows.Microsoft.com
URI Activation for Device Settings
Category Settings page Mobile and/or Desktop Uri
System
Display (on desktop)
Screen (on mobile)
Both ms-settings://screenrotation
Notifications Both ms-settings://notifications
Storage Sense Both ms-settings://storagesense
Battery Saver Both ms-settings://batterysaver
Maps Both ms-settings://maps
Devices Bluetooth Both ms-settings://bluetooth
Network and Wi-fi
Wi-Fi Both ms-settings://network/wifi
Airplane mode Both ms-settings://network/airplanemode
Cellular Both ms-settings://network/cellular
Data Sense Both ms-settings://datasense
NFC Mobile only ms-settings://proximity
Proxy Desktop only ms-settings://network/proxy
More… [See documentation for complete list]
154. http://windows.Microsoft.com
Launch for Results
Launching the app
var options = new LauncherOptions();
options.TargetApplicationPackageFamilyName = "24919.Instap";
var launchUri = new Uri("instapaper:?AddUrl=http%3A%2F%2Fbing.com");
await Launcher.LaunchUriForResultsAsync(launchUri, options, data);
var resultData = new ValueSet();
resultData.Add("Result", value);
operation.ProtocolForResultsOperation.ReportCompleted(resultData);
App1 App2
156. With App Services, store
applications can provide services to
other store applications
157. http://windows.Microsoft.com
What are App Services?
UWP offers many APIs that allow apps to interact with the
platform
• Windows.ApplicationModel.Contacts
• Windows.ApplicationModel.Email
• Windows.System.Launcher.LaunchUriAsync to launch settings, maps, store etc…
• more…
UWP also allows apps to interact with each other
• Uri Associations using LaunchUriAsync
• File associations using LaunchFileAsync
• Launch for results using LaunchUriForResultsAsync
• App Services
161. http://windows.Microsoft.com
AppServiceConnection connection = new AppServiceConnection();
connection.AppServiceName = "microsoftDX-appservicesdemo";
connection.PackageFamilyName = "24919ArunjeetSingh.InstapaperIt";
AppServiceConnectionStatus connectionStatus = await connection.OpenAsync();
if (connectionStatus == AppServiceConnectionStatus.Success)
{
//Send data to the service
var message = new ValueSet();
message.Add("Command", "CalcSum");
message.Add("Value1", Int32.Parse(Value1.Text));
message.Add("Value2", Int32.Parse(Value2.Text));
//Send message and wait for response
AppServiceResponse response = await connection.SendMessageAsync(message);
if (response.Status == AppServiceResponseStatus.Success)
{
int sum = (int)response.Message["Result"];
new MessageDialog("Result=" + sum).ShowAsync();
}
}
else
{
//Drive the user to store to install the app that provides the app service
}
App Services – Client
162. http://windows.Microsoft.com
namespace AppServicesDemoTask
{
public sealed class AppServiceTask : IBackgroundTask
{
private static BackgroundTaskDeferral _serviceDeferral;
public void Run(IBackgroundTaskInstance taskInstance)
{
// Associate a cancellation handler with the background task.
taskInstance.Canceled += TaskInstance_Canceled;
// Get the deferral object from the task instance
_serviceDeferral = taskInstance.GetDeferral();
var appService = taskInstance.TriggerDetails as AppServiceTriggerDetails;
if (appService.Name == "microsoftDX-appservicesdemo")
{
//Maybe ValidateCaller(appService.CallerPackageFamilyName) ??
appService.AppServiceConnection.RequestReceived += RequestReceived;
}
}
...
App Services – Service (1/2)
163. http://windows.Microsoft.com
private async void RequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
{
var message = args.Request.Message;
// This service uses a Command keyed entry for the client to invoke services from the App Service
string command = message["Command"] as string;
switch (command)
{
case "DoIt": {
var messageDeferral = args.GetDeferral();
int value1 = (int)message["Value1"];
... Do some processing
//Set a result to return to the caller
var returnMessage = new ValueSet();
returnMessage.Add("Result", result);
var responseStatus = await args.Request.SendResponseAsync(returnMessage);
messageDeferral.Complete();
break;
}
case "Quit": {
//Service was asked to quit. Complete service deferral so platform can terminate
_serviceDeferral.Complete();
break;
}
App Services – Service (2/2)
165. http://windows.Microsoft.com
Two-way Communication
Client and server can keep a two-way chatty
communication channel open
Client can attach a RequestReceived event handler to its own
AppServiceConnection instance
Both client and server can send and receive messages
AppServiceConnectionStatus connectionStatus = await connection.OpenAsync();
if (connectionStatus == AppServiceConnectionStatus.Success)
{
connection.RequestReceived += OnRequestReceived;
}
If you want to keep support for windows 8.1 you can keep your shared project – and leverage the new compiler directive “WINDOWS_UAP” for Windows 10 specific functionality.
If you want to leverage full UAP targeting Windows 10, instead of compiler directives leverage the new ApiInformation.