Skip to content

Commit a3393c0

Browse files
authored
Add Sample App to demonstrate Share Target (#330)
1 parent 7b3029a commit a3393c0

22 files changed

+406
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This repository hosts samples for the [Windows App SDK](https://github.com/micro
1010
- [Instancing](Samples/AppLifecycle/Instancing): These samples demonstrate support for single and selective multi-instancing.
1111
- [Power Notifications](Samples/AppLifecycle/StateNotifications): These samples demonstrate the power/system state notifications for managing app workload.
1212
- [Restart](Samples/AppLifecycle/Restart): These samples demonstrate synchronously restarting an app with command-line restart arguments.
13+
- [Share Target](Samples\AppLifecycle\ShareTarget\WinUI-CS-ShareTargetSampleApp): This sample demonstrates an app that can be activated as a share target.
1314

1415
#### Data and Files
1516
- [Resource Management](Samples/ResourceManagement): These samples demonstrates app resource management using the MRT Core APIs.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.8.34601.278
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinUI-CS-ShareTargetSampleApp", "WinUI-CS-ShareTargetSampleApp\WinUI-CS-ShareTargetSampleApp.csproj", "{48EF22D2-BC4C-457B-8608-636415989CA5}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|ARM64 = Debug|ARM64
11+
Debug|x64 = Debug|x64
12+
Debug|x86 = Debug|x86
13+
Release|ARM64 = Release|ARM64
14+
Release|x64 = Release|x64
15+
Release|x86 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{48EF22D2-BC4C-457B-8608-636415989CA5}.Debug|ARM64.ActiveCfg = Debug|ARM64
19+
{48EF22D2-BC4C-457B-8608-636415989CA5}.Debug|ARM64.Build.0 = Debug|ARM64
20+
{48EF22D2-BC4C-457B-8608-636415989CA5}.Debug|ARM64.Deploy.0 = Debug|ARM64
21+
{48EF22D2-BC4C-457B-8608-636415989CA5}.Debug|x64.ActiveCfg = Debug|x64
22+
{48EF22D2-BC4C-457B-8608-636415989CA5}.Debug|x64.Build.0 = Debug|x64
23+
{48EF22D2-BC4C-457B-8608-636415989CA5}.Debug|x64.Deploy.0 = Debug|x64
24+
{48EF22D2-BC4C-457B-8608-636415989CA5}.Debug|x86.ActiveCfg = Debug|x86
25+
{48EF22D2-BC4C-457B-8608-636415989CA5}.Debug|x86.Build.0 = Debug|x86
26+
{48EF22D2-BC4C-457B-8608-636415989CA5}.Debug|x86.Deploy.0 = Debug|x86
27+
{48EF22D2-BC4C-457B-8608-636415989CA5}.Release|ARM64.ActiveCfg = Release|ARM64
28+
{48EF22D2-BC4C-457B-8608-636415989CA5}.Release|ARM64.Build.0 = Release|ARM64
29+
{48EF22D2-BC4C-457B-8608-636415989CA5}.Release|ARM64.Deploy.0 = Release|ARM64
30+
{48EF22D2-BC4C-457B-8608-636415989CA5}.Release|x64.ActiveCfg = Release|x64
31+
{48EF22D2-BC4C-457B-8608-636415989CA5}.Release|x64.Build.0 = Release|x64
32+
{48EF22D2-BC4C-457B-8608-636415989CA5}.Release|x64.Deploy.0 = Release|x64
33+
{48EF22D2-BC4C-457B-8608-636415989CA5}.Release|x86.ActiveCfg = Release|x86
34+
{48EF22D2-BC4C-457B-8608-636415989CA5}.Release|x86.Build.0 = Release|x86
35+
{48EF22D2-BC4C-457B-8608-636415989CA5}.Release|x86.Deploy.0 = Release|x86
36+
EndGlobalSection
37+
GlobalSection(SolutionProperties) = preSolution
38+
HideSolutionNode = FALSE
39+
EndGlobalSection
40+
GlobalSection(ExtensibilityGlobals) = postSolution
41+
SolutionGuid = {1FF2E4F9-2325-4BA5-8F6A-2A411D1C52C0}
42+
EndGlobalSection
43+
EndGlobal
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!-- Copyright (c) Microsoft Corporation.
2+
Licensed under the MIT License. -->
3+
<Application
4+
x:Class="WinUI_CS_ShareTargetSampleApp.App"
5+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
6+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
7+
xmlns:local="using:WinUI_CS_ShareTargetSampleApp">
8+
<Application.Resources>
9+
<ResourceDictionary>
10+
<ResourceDictionary.MergedDictionaries>
11+
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
12+
<!-- Other merged dictionaries here -->
13+
</ResourceDictionary.MergedDictionaries>
14+
<!-- Other app resources here -->
15+
</ResourceDictionary>
16+
</Application.Resources>
17+
</Application>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using Microsoft.UI.Xaml;
5+
using Microsoft.UI.Xaml.Controls;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using Windows.ApplicationModel.Activation;
10+
using Windows.ApplicationModel.DataTransfer;
11+
12+
namespace WinUI_CS_ShareTargetSampleApp
13+
{
14+
public partial class App : Application
15+
{
16+
public App()
17+
{
18+
this.InitializeComponent();
19+
}
20+
21+
/// <summary>
22+
/// Invoked when the application is launched.
23+
/// </summary>
24+
/// <param name="args">Details about the launch request and process.</param>
25+
protected override async void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
26+
{
27+
List<string> sharedFilePaths = null;
28+
29+
// Note: In Package.appxmanifest, we declare that this app can be launched as a Share Target.
30+
31+
// Check if this app was launched as a Share Target:
32+
var activationArguments = Windows.ApplicationModel.AppInstance.GetActivatedEventArgs();
33+
if(activationArguments.Kind == ActivationKind.ShareTarget)
34+
{
35+
ShareTargetActivatedEventArgs shareArgs = activationArguments as ShareTargetActivatedEventArgs;
36+
37+
// Get the shared data from the ShareOperation:
38+
shareArgs.ShareOperation.ReportStarted();
39+
if (shareArgs.ShareOperation.Data.Contains(StandardDataFormats.StorageItems))
40+
{
41+
var storageItems = await shareArgs.ShareOperation.Data.GetStorageItemsAsync();
42+
sharedFilePaths = storageItems.Select(item => item.Path).ToList();
43+
}
44+
45+
// Once we have received the shared data from the ShareOperation, call ReportCompleted()
46+
shareArgs.ShareOperation.ReportCompleted();
47+
}
48+
49+
m_window = new MainWindow();
50+
Frame rootFrame = m_window.Content as Frame;
51+
rootFrame.Navigate(typeof(MainPage), sharedFilePaths);
52+
m_window.Activate();
53+
}
54+
55+
private Window m_window;
56+
}
57+
}
Loading
Loading
Loading
Loading
Loading
456 Bytes
Loading

0 commit comments

Comments
 (0)