Silverlight apps on Windows Phone 8.1
Building Apps for Windows Phone 8.1 Jump Start
Silverlight 8.1
Phone Only
In this module…
The XAML frameworks on Windows Phone 8.1Why stay on Windows Phone Silverlight?Upgrading to Silverlight 8.1Changes to the App LifecycleChanges to Tiles and Notifications
Windows Runtime
XAML Frameworks on Windows Phone 8.1
Silverlight
4
Windows Developer Platform in 8.1
Windows Runtime API Set
Graphics Audio Media
Networking File System Input
Commerce
Sensors
.NET CLRWindows Runtime (WinRT)
DirectX(C++)
Windows PhoneSilverlight(C# | VB)
Windows XAML
(C# | VB | C++)
WinJS(HTML + JS)
App Model Services
Navigation
Packaging
Contracts
Background
Store(s)
Push
Roaming
Windows Kernel
App Data Backup
Legend
Windows Phone Only
Windows OnlyWindows + Windows Phone
Windows Phone HistoryWP 7.0Silverlig
ht
WP 7.5Silverlig
ht
WP 8.0Silverlig
ht
WP 8.1Silverlig
ht
WP 8.1WinRT
W 8.0WinRT
W 8.1WinRT
• Existing Code Investment• Supporting 8.1 app and 8.0 app from a single
code base• Not yet converged
• Camera Lenses• VoIP• Lock Screen Wallpaper.• Clipboard API• Simple Sound Effects (XNA)• Run Under Lock Screen
Why stay on Windows Phone Silverlight?
We preserve your investment
Why Retarget Silverlight 8.0 app to Silverlight 8.1? Access to SD Cards Geofencing App to App SSO Share contract And much more…
9
New features available to Silverlight 8.1 appsUpgraded apps can access most of the new 8.1 WinRT APIsBackground
Tasks & Triggers
FileOpenPickerFileSavePick
er
WNS Notification
s
New Tile Templates
Action Center Management
App Data Roaming &
Backup
Credential Locker
Share Source/Targ
et
SD card r/w access
GeoFencing
Email with Attachments
SL XAML/ Direct3D
enhancements
Bluetooth LE and RFCOMM
Cryptography Web Authenticatio
n Broker
WNS Push Notification
Trigger
Storage Provider/Picker Provider
Known Folders
Appointments/Calendar
enhancements
Accessibility (UIA, Large Text, High Contrast)
• Over 90% Windows Runtime API Convergence
• Small set not of features not available in Windows XAML apps yet
ConvergencePhone Feature Only Available in Silverlight
Lenses Support
VOIP Support
Camera Capture Task
Clipboard APIs
Lock Screen Wallpaper API
Ringtone Provider / Alarm & Reminders
Simple Sound effects (XNA)
Run Under Lock Screen
Photos Extensibility
Search Extras
Retargeting your app to Silverlight 8.1
demo
12
When You Retarget To Silverlight 8.1Your app runs in the new WinRT hostThere will be platform behavior changes you’ll need to adjust your code for
Your app has access to new Windows Phone 8.1 APIsExpanded assembly reference set and WinMD
Package.appxmanifest is added to your solutionFor any modern specific app settings
You can use Silverlight background agents and WinRT background tasksOne exception is Silverlight background audio agents
Breaking Changes
Windows Runtime
Apps with XAML
C#/VB or C++
Silverlight 8.1 XAML
C#/VB
WinRTWindows Phone OS 8.1 Libraries
.NET BCL
Silverlight 8.0 XAML
C#/VB
Silverlight 8.0 execution
stack
Modern execution stack
See: Platform compatibility and breaking changes for Windows Phone Silverlight 8.1 apps in MSDN
WinRTWP 8.0
Libraries
.NET BCL
Windows Phone OS 8.1
When you retarget to Silverlight 8.1, you change the execution framework and the librariesCLR/Silverlight bug fixesAPIs may throw different/new exceptions
Documentation with full list
14
Background execution in Silverlight 8.1 apps
Silverlight 8.0
Foreground app
Periodic & Resource-Intensive Background
Agents
CBE: Run-trackers and turn-by-turn
navigation
Background AudioPlayerAgent,
AudioStreamingAgent
Silverlight 8.1
Foreground app
SL Periodic & Resource-Intensive
Background Agents
WinRT Background
Audio
WinRT Background
Tasks
CBE: Run-trackers and turn-by-turn
navigation
Background AudioPlayerAgent
, AudioStreamingA
gent
Adding new features
demo
16
App Lifecycle Changes for Silverlight 8.1
17
App behavior differences
Hitting back terminates the app just like Silverlight 8.0Different from the behavior of Windows Runtime XAML apps, which are suspendedCan force your app to use Windows Runtime app behavior by setting NavigationService.PauseOnBack to true
Silverlight 8.1 apps resume instead of replace on re-launchFast App Resume (FAR) is the *only* optionMatches Windows Runtime XAML app behavior – though ‘Back’ on first page terminates app
This is how FAR is selected in Silverlight 8.0 apps
• You have to edit the file by hand, there is no GUI for this
8.0: Enabling FAR in Properties\WMAppManifest.xml
<Tasks> <DefaultTask Name ="_default" NavigationPage="MainPage.xaml"/></Tasks>
<Tasks> <DefaultTask Name ="_default" NavigationPage="MainPage.xaml" ActivationPolicy="Resume"></Tasks>
Act
ive
Su
spen
de
d
FAR-enabled App Behavior
same
20
What do I need to do about FAR?In most cases - nothingApp templates already have ‘plumbing’ code in to make app give the same user experience on ‘Resume’ as if it is ‘Replace’Clears navigation backstackRestarts on apps ‘normal’ launch page
You may choose to change this if you want different user experience
private void InitializePhoneApplication(){ ...
// Handle reset requests for clearing the backstack RootFrame.Navigated += CheckForResetNavigation;
...}
Adding FAR handling to your Silverlight 8.1 appdemo
22
Continuing your Silverlight 8.1 app after calling a file picker
23
Contract ActivationsThe following new APIs cause the app to be activated as part of a contract:• Share contract• FileOpenPicker, FileSavePicker• WebAuthenticationBroker
Silverlight 8.1 new project templates already hook up ContractActivated event handlerAdd this to your upgraded 8.0 projects
private void InitializePhoneApplication(){ ... // Handle contract activation such as a file open or save picker PhoneApplicationService.Current.ContractActivated += Application_ContractActivated; ...}
24
Picker Contracts – Pick/Save a FileUsage Differs on Windows and Windows Phone
//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...}
Windows
//Create the picker object FileOpenPicker openPicker = new FileOpenPicker();
// 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 openPicker.ContinuationData["Operation"] = "SomeDataOrOther"; openPicker.PickSingleFileAndContinue();
Windows Phone
App suspended, may be terminated
App activated when file picked
Activation after File Picker (Silverlight 8.1)1 of 2 – App.xaml.cs sealed partial class App : Application
{
...
// Property to store the args on a File Picker activation public FileOpenPickerContinuationEventArgs FilePickerContinuationArgs { get; set; }
// Code to execute when the application is activated (brought to foreground) // This code will not execute when the application is first launched private void Application_ContractActivated(object sender, IActivatedEventArgs e) { var filePickerContinuationArgs = e as FileOpenPickerContinuationEventArgs;
//Event args is of type FileOpenPickerContinuationEventArgs so execute share target behavior if (filePickerContinuationArgs != null) { this.FilePickerContinuationArgs = filePickerContinuationArgs; } }
Activation after File Picker (Silverlight 8.1)2 of 2 – Page where picker was initiated public partial class ProfilePage : PhoneApplicationPage { ... protected override void OnNavigatedTo(NavigationEventArgs e) { var app = App.Current as App; if (app.FilePickerContinuationArgs != null) { this.ContinueFileOpenPicker(app.FilePickerContinuationArgs); } }
public async void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args) { // Same as in Windows XAML example... ... }
27
Implementing Providers in Silverlight 8.1
Silverlight 8.1 apps can also be configured to act as Providers – the app the user chooses to complete sharing, or to pick/save a fileShare TargetApp the user selects in the Share picker UI to receive content another app is ahring
FileOpenPicker or FileSavePicker ProviderApp the user selects in the Picker UI to select a file for opening/saving
Not covered in this Jump Start See MSDN documentation for details
28
Contract Activations
demo
29
Windows Notification Services on Silverlight 8.1
30
Notifications Services in Silverlight 8.1 apps
Silverlight 8.0
app
Silverlight 8.1
MPNS
app
MPNS WNS
MPNS WNS
or? ?
WNS is better!• Notifications delivered
within 5 seconds to devices connected to a network
• No more certifications to manage: WNS uses OAuth instead of SSL certification
• Convergence with Windows Store Apps
• Many improved features compared to MPNS
31
Opting into WNS
Select WNS Notification Service in WMAppManifest.xml
32
Specify Tile and Icon assets in package.appxmanifest <?xml version="1.0" encoding="utf-8"?> <Package xmlns=http://schemas.microsoft.com/appx/2010/manifest ... /> ... <Applications> <Application Id="App" Executable="AGHost.exe" EntryPoint="MainPage.xaml"> <m3:VisualElements DisplayName="TileUpdateAfterDeactivation" Square150x150Logo="Assets\SquareTile150x150.png" Square44x44Logo="Assets\Logo.png" Description="TileUpdateAfterDeactivation" ForegroundText="light" BackgroundColor="#00b2f0"> <m3:DefaultTile Square71x71Logo="Assets\SquareTile71x71.png"/> <m3:SplashScreen Image="Assets\SplashScreen.png" /> <m3:ApplicationView MinWidth="width320"/> <!--Used in XAML Designer. DO NOT REMOVE--> </m3:VisualElements>
... </Package>
33
Other considerations…
When upgrading to WNS, consider the following:• Set ToastCapable = true in your app's Package.appxmanifest file if you
raise toasts• Cycle tile not supported. Consider using the tile notification queue and a
peek template.• Flip tile not supported. Use peek tile templates or a tile notification
queue.• Make sure to use the Silverlight page-centric navigation model e.g.,
“/Page2.xaml?how=toast”• When using RequestCreateAsync() to pin a secondary tile, on
Windows Phone the app will be immediately suspended (different from Windows). You should update a pinned tile in the Deactivated event of your app.
• Make sure you have no using statements for the MPNS namespaces (Microsoft.Phone.Notification, Microsoft.Phone.Shell.*Tile* or Microsoft.Phone.Shell.ShellToast) declared anywhere in your code
34
Pinning a secondary tile using WNS APIs private async void PinAndUpdate_Click(object sender, RoutedEventArgs e) { // Create the original Square150x150 tile var tile = new SecondaryTile(SCENARIO1_TILEID, "Scenario 1", "/MainPage.xaml?scenario=Scenario1", new Uri("ms-appx:///Assets/originalTileImage.png"), TileSize.Default);
tile.VisualElements.ShowNameOnSquare150x150Logo = true; await tile.RequestCreateAsync();
// When a new tile is created, app will be deactivated and the new tile will be displayed on the start screen.
// Any code after the call to RequestCreateAsync is not guaranteed to run. // For example, updating the new secondary tile with additional data // If the app is deactivated before reaching this point, the following code will never run.
// Update the tile we created using a notification. var tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150Image); ... updater.Update(notification); }
Will never run!
35
Solution: Invoke tile update code on deactivate public partial class App : Application { /// <summary> /// This delegate is invoked during Deactivate when a new tile is pinned. /// It's important to set this property before calling SecondaryTile.RequestCreateAsync() /// </summary> public static Action OnNewTilePinned { get; set; } ... private void Application_Deactivated(object sender, DeactivatedEventArgs e) { if (OnNewTilePinned != null) { OnNewTilePinned(); OnNewTilePinned = null; } }
...
36
Updating a pinned tile on deactivation
demo
App Submission
Silverlight 8.1 App Deployment
Silverlight 8.1 app runs on 8.1 Phones Only
Store supports 3 versions per app side-by-side• 8.1• 8.0• 7.1
Silverlight 8.1 apps require that you manually edit Package.appxmanifest before submission!See topic Prepare your Windows Phone Silverlight 8.1 app for publishing in MSDN documentation
Step 1: Reserve an App Name
App Name
Package Identity NamePublisher Name
Step 2: Edit AppXManifest.xml
App Name
Package Identity NamePublisher
Name
Step 3: WMAppManifest.xml
App Name
See topic Prepare your Windows Phone Silverlight 8.1 app for publishing in MSDN documentation for details
42
Summary
Which XAML Framework should you use?App Type Framework
New App WinRT or Silverlight
Existing Windows Store App WinRT
Lock Screen Image (social, weather, sports, ..)
Silverlight 8.x
Camera Based App (lenses integration) or VOIP
Silverlight 8.x
Music App Silverlight 8.0 or WinRT
Existing Silverlight Phone Apps Silverlight 8.x or WinRT
Wrap Up
Windows Runtime XAML vs Silverlight Frameworks
New WinRT APIsAdd value to your existing apps today
Protecting your investmentsNew code can be easily ported to XAMLPortable Class Libraries can now target Silverlight and XAML Apps
©2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Top Related