Operation system provides an association of the specified file or URI which can run the default app. We can also use the feature in our apps. The Launcher class in Windows.System namespace gives LaunchUriAsync method which calls the feature.
The View Model is useful when providing values which changes dynamic, but static values such as an url of privacy policy or terms of use and so on are better provided from LaunchUriAsync method, because the link strings “privacy policy” or “terms of use” are fixed with static values.

・XAML

If needs the copy, use the GitHub Gist at end of this article.

>>Sample solution for Visual Studio 2017

The reason of using simple click handler is the link strings “privacy (policy)” holds static values without a conditional branch. So the Content value of the HyperlinkButton holds the URL as the Tag value.

・XAML.cs

The Tag value of the HyperlinkButton is acquired at the Footer_Click event handler as the Tag value of the sender which is casted to HyperlinkButton object.

・XAML

<Page
x:Class="StatefulMiddleWareUWP.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:StatefulMiddleWareUWP"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<RelativePanel Background="#ff000000">
<TextBlock x:Name="Header" Text="{x:Bind ViewModel.Title}" Style="{StaticResource HeaderTextBlockStyle}" Margin="10,60,0,0" Foreground="White"/>
<TextBlock x:Name="ProfileCreatorTitle" Text="{x:Bind ViewModel.Lead}" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="Wrap" RelativePanel.Below="Header" Margin="10,10,0,0" Foreground="White"/>
<ListBox x:Name="MenuList" SelectionChanged="MenuList_SelectionChanged"
SelectionMode="Single" HorizontalAlignment="Left" VerticalAlignment="Top" RelativePanel.Below="ProfileCreatorTitle" Margin="0,20,0,0" ItemsSource="{x:Bind ViewModel.Menu}">
<ListBox.ItemTemplate>
<DataTemplate x:DataType="local:MenuContext">
<TextBlock Text="{x:Bind Title}" Style="{StaticResource BaseTextBlockStyle}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<StackPanel x:Name="FooterPanel" Orientation="Vertical" RelativePanel.AlignBottomWithPanel="True">
<TextBlock x:Name="Copyright" Text="Processtune. All rights reserved." Style="{StaticResource CaptionTextBlockStyle}" RelativePanel.Above="LinksPanel" Margin="10,10,0,0" Foreground="White"/>
<StackPanel x:Name="LinksPanel" Orientation="Horizontal" Margin="10,10,0,10">
<HyperlinkButton Content="Trademarks" Tag="http://blog.processtune.com"
Click="Footer_Click" FontSize="12" Style="{StaticResource TextBlockButtonStyle}" Foreground="#FF00FF00" />
<TextBlock Text="|" Style="{StaticResource CaptionTextBlockStyle}" VerticalAlignment="Center" Foreground="White" Margin="10,0" />
<HyperlinkButton x:Name="PrivacyLink" Content="Privacy" Tag="http://blog.processtune.com/?page_id=441" Click="Footer_Click" FontSize="12" Style="{StaticResource TextBlockButtonStyle}" Foreground="#FF00FF00"/>
</StackPanel>
</StackPanel>
</RelativePanel>
</Grid>
</Page>

・XAML.cs

using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
// 空白ページの項目テンプレートについては、https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x411 を参照してください
namespace StatefulMiddleWareUWP
{
/// <summary>
/// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。
/// </summary>
public sealed partial class MainPage : Page
{
public MainVM ViewModel { get; set; }
public MainPage()
{
this.InitializeComponent();
ViewModel = new MainVM();
}
private void MenuList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListBox menuListBox = sender as ListBox;
}
async void Footer_Click(object sender, RoutedEventArgs e)
{
await Windows.System.Launcher.LaunchUriAsync(new Uri(((HyperlinkButton)sender).Tag.ToString()));
}
}
}

Tags:

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *