Feb 172014
 
 February 17, 2014  Posted by at 8:02 am WinRT  Add comments

LauncherOptions has several neat properties that lets us configure the launch for a better user experience. You might for example want the user to use a specific application, and suggest that they download it if itโ€™s not installed. This is done with:

PreferredApplicationDisplayName and PreferredApplicationPackageFamilyName

If you want the user to select from a list of applications that have registered for the file type you can use:

DisplayApplicationPicker

LauncherOptions2

Another cool feature, which my friend Jonas showed me, was:

DesiredRemainingView

One of the most exciting features of Windows Store Apps is for me the ability to run applications side by side. Not so surprisingly you can therefore launch a target application to for example open a specified file, pushing your application to the side in medium or minimum mode, and having the other application take up the remainder of the space. This is done with DesiredRemainingView.

LauncherOptions

These are just small tweaks that add to the overall user experience, but all the small things here and there add up, and helps us deliver better applications that our users want to use- and enjoy to use.

Make sure you add some thought to how you launch files in applications, and use the LauncherOptions object.

Code example:

Codebehind

[sourcecode language=”csharp”]
using System;
using Windows.Storage;
using Windows.System;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;

namespace SnapToSide
{

public sealed partial class MainPage : Page
{
public MainPage()
{
InitializeComponent();
SizeChanged += OnSizeChanged;
}

private void OnSizeChanged(object sender, SizeChangedEventArgs sizeChangedEventArgs)
{
VisualStateManager.GoToState(this, sizeChangedEventArgs.NewSize.Width <= 320 ? "Small" : "Default", true);
}

private async void TextBlock_Tapped(object sender, TappedRoutedEventArgs e)
{
var pdf = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///file.pdf"));

await
Launcher.LaunchFileAsync(pdf,
new LauncherOptions
{
DisplayApplicationPicker = true,
DesiredRemainingView = ViewSizePreference.UseMinimum
});
}
}
}
[/sourcecode]

View

[sourcecode language=”xml”]
<Page
x:Class="SnapToSide.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SnapToSide"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="#FF2E3B46">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock x:Name="textBlock" Text="PDF Viewer" FontSize="65" Margin="20,50" HorizontalAlignment="Center" TextWrapping="Wrap"/>
<TextBlock x:Name="textBlock1" Grid.Row="1" Text="Open pdf and snap to the side" FontSize="65" Margin="20,50" Foreground="orange" HorizontalAlignment="Center" Tapped="TextBlock_Tapped" TextWrapping="Wrap"/>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="Small">
<Storyboard>
<DoubleAnimation Duration="0" To="32" Storyboard.TargetProperty="(TextBlock.FontSize)" Storyboard.TargetName="textBlock" d:IsOptimized="True"/>
<DoubleAnimation Duration="0" To="32" Storyboard.TargetProperty="(TextBlock.FontSize)" Storyboard.TargetName="textBlock1" d:IsOptimized="True"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Default"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</Page>
[/sourcecode]

Images in case code examples get messed up in the future ๐Ÿ™‚

 

LauncherOptions4

 

LauncherOptions3

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

What is 3 + 12 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)