forked from microsoft/Windows-universal-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scenario1_LaunchFile.xaml.vb
141 lines (129 loc) · 6.3 KB
/
Scenario1_LaunchFile.xaml.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
'*********************************************************
'
' Copyright (c) Microsoft. All rights reserved.
' This code is licensed under the MIT License (MIT).
' THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
' ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
' IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
' PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
'
'*********************************************************
Imports System
Imports System.Threading.Tasks
Imports Windows.ApplicationModel.Activation
Imports Windows.Foundation
Imports Windows.Storage
Imports Windows.System
Imports Windows.UI.Xaml
Imports Windows.UI.Xaml.Controls
Imports Windows.UI.Xaml.Navigation
Namespace Global.SDKTemplate
''' <summary>
''' An empty page that can be used on its own or navigated to within a Frame.
''' </summary>
Partial Public NotInheritable Class Scenario1_LaunchFile
Inherits Page
Dim rootPage As MainPage = MainPage.Current
Dim fileToLaunch As String = "Assets\microsoft-sdk.png"
Public Sub New()
Me.InitializeComponent()
ViewPreference.ItemsSource = MainPage.ViewSizePreferences
ViewPreference.SelectedIndex = 0
End Sub
Private Async Function GetFileToLaunch() As Task(Of StorageFile)
' First, get the image file from the package's image directory.
Dim file = Await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(fileToLaunch)
file = Await file.CopyAsync(ApplicationData.Current.TemporaryFolder, "filetolaunch.png", NameCollisionOption.ReplaceExisting)
Return file
End Function
' Launch a .png file that came with the package.
''' <summary>
Private Async Sub LaunchFileDefault()
' First, get the image file from the package's image directory.
Dim file = Await GetFileToLaunch()
' Next, launch the file.
Dim success As Boolean = Await Launcher.LaunchFileAsync(file)
If success Then
rootPage.NotifyUser("File launched: " & file.Name, NotifyType.StatusMessage)
Else
rootPage.NotifyUser("File launch failed.", NotifyType.ErrorMessage)
End If
End Sub
' Launch a .png file that came with the package. Show a warning prompt.
''' <summary>
Private Async Sub LaunchFileWithWarning()
' First, get the image file from the package's image directory.
Dim file = Await GetFileToLaunch()
' Next, configure the warning prompt.
Dim options = New LauncherOptions() With {.TreatAsUntrusted = True}
' Finally, launch the file.
Dim success As Boolean = Await Launcher.LaunchFileAsync(file, options)
If success Then
rootPage.NotifyUser("File launched: " & file.Name, NotifyType.StatusMessage)
Else
rootPage.NotifyUser("File launch failed.", NotifyType.ErrorMessage)
End If
End Sub
' Launch a .png file that came with the package. Show an Open With dialog that lets the user chose the handler to use.
''' <summary>
Private Async Sub LaunchFileOpenWith(sender As Object, e As RoutedEventArgs)
' First, get the image file from the package's image directory.
Dim file = Await GetFileToLaunch()
' Calculate the position for the Open With dialog.
' An alternative to using the point is to set the rect of the UI element that triggered the launch.
Dim openWithPosition As Point = MainPage.GetElementLocation(sender)
' Next, configure the Open With dialog.
Dim options = New LauncherOptions()
options.DisplayApplicationPicker = True
options.UI.InvocationPoint = openWithPosition
options.UI.PreferredPlacement = Windows.UI.Popups.Placement.Below
' Finally, launch the file.
Dim success As Boolean = Await Launcher.LaunchFileAsync(file, options)
If success Then
rootPage.NotifyUser("File launched: " & file.Name, NotifyType.StatusMessage)
Else
rootPage.NotifyUser("File launch failed.", NotifyType.ErrorMessage)
End If
End Sub
' Launch a .png file that came with the package. Request to share the screen with the launched app.
''' <summary>
Private Async Sub LaunchFileSplitScreen()
' First, get a file via the picker.
Dim openPicker = New Pickers.FileOpenPicker()
openPicker.FileTypeFilter.Add("*")
Dim file As StorageFile = Await openPicker.PickSingleFileAsync()
If file IsNot Nothing Then
' Configure the request for split screen launch.
Dim options = New LauncherOptions() With {.DesiredRemainingView = ViewPreference.SelectedValue}
' Next, launch the file.
Dim success As Boolean = Await Launcher.LaunchFileAsync(file, options)
If success Then
rootPage.NotifyUser("File launched: " & file.Name, NotifyType.StatusMessage)
Else
rootPage.NotifyUser("File launch failed.", NotifyType.ErrorMessage)
End If
Else
rootPage.NotifyUser("No file was picked.", NotifyType.ErrorMessage)
End If
End Sub
' Have the user pick a file, then launch it.
''' <summary>
Private Async Sub PickAndLaunchFile()
' First, get a file via the picker.
Dim openPicker = New Pickers.FileOpenPicker()
openPicker.FileTypeFilter.Add("*")
Dim file As StorageFile = Await openPicker.PickSingleFileAsync()
If file IsNot Nothing Then
' Next, launch the file.
Dim success As Boolean = Await Launcher.LaunchFileAsync(file)
If success Then
rootPage.NotifyUser("File launched: " & file.Name, NotifyType.StatusMessage)
Else
rootPage.NotifyUser("File launch failed.", NotifyType.ErrorMessage)
End If
Else
rootPage.NotifyUser("No file was picked.", NotifyType.ErrorMessage)
End If
End Sub
End Class
End Namespace