Skip to content

Commit 97aba78

Browse files
committed
Remove MainPage from the UWP tray host project
1 parent 9ded4e3 commit 97aba78

File tree

11 files changed

+183
-187
lines changed

11 files changed

+183
-187
lines changed

samples/TrayIconFlyout.Uwp.Sample.Packaging/Package.appxmanifest

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,44 @@
55
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
66
IgnorableNamespaces="uap mp">
77

8-
<Identity Name="5270f1ab-c78a-4f29-a964-3886d725e183" Publisher="CN=0x5BFA" Version="1.0.0.0" />
9-
10-
<mp:PhoneIdentity PhoneProductId="5270f1ab-c78a-4f29-a964-3886d725e183" PhonePublisherId="5270f1ab-c78a-4f29-a964-3886d725e183"/>
11-
12-
<Properties>
13-
<DisplayName>TrayIconFlyout sample app (UWP)</DisplayName>
14-
<PublisherDisplayName>0x5BFA</PublisherDisplayName>
15-
<Logo>Assets\StoreLogo.png</Logo>
16-
</Properties>
17-
18-
<Dependencies>
19-
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
20-
</Dependencies>
21-
22-
<Resources>
23-
<Resource Language="x-generate"/>
24-
</Resources>
25-
26-
<Applications>
27-
<Application Id="App"
28-
Executable="$targetnametoken$.exe"
29-
EntryPoint="windows.fullTrustApplication">
30-
<uap:VisualElements
31-
DisplayName="TIF sample app (UWP)"
32-
Description="TrayIconFlyout sample app (UWP)"
33-
BackgroundColor="transparent"
34-
Square150x150Logo="Assets\Square150x150Logo.png"
35-
Square44x44Logo="Assets\Square44x44Logo.png">
36-
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" />
37-
<uap:SplashScreen Image="Assets\SplashScreen.png" />
38-
</uap:VisualElements>
39-
<Extensions>
40-
<uap:Extension Category="windows.protocol" Executable="TrayIconFlyout.Uwp.Sample.SecondaryApp\TrayIconFlyout.Uwp.Sample.SecondaryApp.exe" EntryPoint="App2">
41-
<uap:Protocol Name="tif-secondaryapp">
42-
<uap:DisplayName>TIF</uap:DisplayName>
43-
</uap:Protocol>
44-
</uap:Extension>
45-
</Extensions>
46-
</Application>
47-
</Applications>
48-
49-
<Capabilities>
50-
<rescap:Capability Name="runFullTrust" />
51-
</Capabilities>
8+
<Identity Name="5270f1ab-c78a-4f29-a964-3886d725e183" Publisher="CN=0x5BFA" Version="1.0.0.0" />
9+
10+
<mp:PhoneIdentity PhoneProductId="5270f1ab-c78a-4f29-a964-3886d725e183" PhonePublisherId="5270f1ab-c78a-4f29-a964-3886d725e183"/>
11+
12+
<Properties>
13+
<DisplayName>TrayIconFlyout sample app (UWP)</DisplayName>
14+
<PublisherDisplayName>0x5BFA</PublisherDisplayName>
15+
<Logo>Assets\StoreLogo.png</Logo>
16+
</Properties>
17+
18+
<Dependencies>
19+
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
20+
</Dependencies>
21+
22+
<Resources>
23+
<Resource Language="x-generate"/>
24+
</Resources>
25+
26+
<Applications>
27+
<Application Id="App" Executable="TrayIconFlyout.Uwp.Sample.TrayHost\TrayIconFlyout.Uwp.Sample.TrayHost.exe" EntryPoint="Windows.FullTrustApplication">
28+
<uap:VisualElements DisplayName="TIF sample app (UWP)" Description="TrayIconFlyout sample app (UWP)" BackgroundColor="transparent" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png">
29+
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" />
30+
<uap:SplashScreen Image="Assets\SplashScreen.png" />
31+
</uap:VisualElements>
32+
33+
<Extensions>
34+
<uap:Extension Category="windows.protocol" Executable="TrayIconFlyout.Uwp.Sample.SecondaryApp\TrayIconFlyout.Uwp.Sample.SecondaryApp.exe" EntryPoint="App2">
35+
<uap:Protocol Name="tif-secondaryapp">
36+
<uap:DisplayName>TIF</uap:DisplayName>
37+
</uap:Protocol>
38+
</uap:Extension>
39+
</Extensions>
40+
41+
</Application>
42+
</Applications>
43+
44+
<Capabilities>
45+
<rescap:Capability Name="runFullTrust" />
46+
</Capabilities>
5247

5348
</Package>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Application
2-
x:Class="TrayIconFlyout.Uwp.Sample.SecondaryApp.App2"
3-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5-
xmlns:local="using:TrayIconFlyout.Uwp.Sample.SecondaryApp" />
2+
x:Class="U5BFA.Libraries.App2"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:U5BFA.Libraries" />
Lines changed: 45 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,64 @@
1-
using System;
1+
// Copyright (c) 0x5BFA. All rights reserved.
2+
// Licensed under the MIT license.
23

4+
using System;
35
using Windows.ApplicationModel;
46
using Windows.ApplicationModel.Activation;
57
using Windows.UI.Xaml;
68
using Windows.UI.Xaml.Controls;
79
using Windows.UI.Xaml.Navigation;
8-
910
using WinRT;
1011

11-
namespace TrayIconFlyout.Uwp.Sample.SecondaryApp;
12-
/// <summary>
13-
/// Provides application-specific behavior to supplement the default <see cref="Application"/> class.
14-
/// </summary>
15-
public sealed partial class App2 : Application
12+
namespace U5BFA.Libraries
1613
{
17-
/// <summary>
18-
/// Initializes the singleton application object. This is the first line of authored code
19-
/// executed, and as such is the logical equivalent of main() or WinMain().
20-
/// </summary>
21-
public App2()
22-
{
23-
InitializeComponent();
14+
public sealed partial class App2 : Application
15+
{
16+
public App2()
17+
{
18+
InitializeComponent();
2419

25-
Suspending += OnSuspending;
26-
}
20+
Suspending += OnSuspending;
21+
}
2722

28-
protected override void OnActivated(IActivatedEventArgs args)
29-
{
30-
// Do not repeat app initialization when the Window already has content,
31-
// just ensure that the window is active.
32-
if (Window.Current.Content is not Frame rootFrame)
33-
{
34-
// Create a Frame to act as the navigation context and navigate to the first page
35-
rootFrame = new Frame();
36-
rootFrame.NavigationFailed += OnNavigationFailed;
23+
protected override void OnActivated(IActivatedEventArgs args)
24+
{
25+
// Do not repeat app initialization when the Window already has content,
26+
// just ensure that the window is active.
27+
if (Window.Current.Content is not Frame rootFrame)
28+
{
29+
// Create a Frame to act as the navigation context and navigate to the first page
30+
rootFrame = new Frame();
31+
rootFrame.NavigationFailed += OnNavigationFailed;
3732

38-
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
39-
{
40-
// TODO: Load state from previously suspended application
41-
}
33+
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
34+
{
35+
// TODO: Load state from previously suspended application
36+
}
4237

43-
// Place the frame in the current Window
44-
Window.Current.Content = rootFrame;
45-
}
38+
// Place the frame in the current Window
39+
Window.Current.Content = rootFrame;
40+
}
4641

47-
if (rootFrame.Content == null)
48-
{
49-
rootFrame.Navigate(typeof(MainPage2), args.As<ProtocolActivatedEventArgs>().Data);
50-
}
42+
if (rootFrame.Content == null)
43+
{
44+
rootFrame.Navigate(typeof(MainPage), args.As<ProtocolActivatedEventArgs>().Data);
45+
}
5146

52-
// Ensure the current window is active
53-
Window.Current.Activate();
54-
}
47+
// Ensure the current window is active
48+
Window.Current.Activate();
49+
}
5550

56-
/// <summary>
57-
/// Invoked when Navigation to a certain page fails.
58-
/// </summary>
59-
/// <param name="sender">The Frame which failed navigation.</param>
60-
/// <param name="e">Details about the navigation failure.</param>
61-
private void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
62-
{
63-
throw new Exception($"Failed to load page '{e.SourcePageType.FullName}'.");
64-
}
51+
private void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
52+
{
53+
throw new Exception($"Failed to load page '{e.SourcePageType.FullName}'.");
54+
}
6555

66-
/// <summary>
67-
/// Invoked when application execution is being suspended. Application state is saved
68-
/// without knowing whether the application will be terminated or resumed with the contents
69-
/// of memory still intact.
70-
/// </summary>
71-
/// <param name="sender">The source of the suspend request.</param>
72-
/// <param name="e">Details about the suspend request.</param>
73-
private void OnSuspending(object sender, SuspendingEventArgs e)
74-
{
75-
SuspendingDeferral deferral = e.SuspendingOperation.GetDeferral();
56+
private void OnSuspending(object sender, SuspendingEventArgs e)
57+
{
58+
SuspendingDeferral deferral = e.SuspendingOperation.GetDeferral();
7659

77-
// TODO: Save application state and stop any background activity
78-
deferral.Complete();
79-
}
60+
// TODO: Save application state and stop any background activity
61+
deferral.Complete();
62+
}
63+
}
8064
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Page
2+
x:Class="U5BFA.Libraries.MainPage"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="using:U5BFA.Libraries"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
9+
mc:Ignorable="d">
10+
11+
<Grid>
12+
<StackPanel
13+
HorizontalAlignment="Center"
14+
VerticalAlignment="Center"
15+
Orientation="Vertical">
16+
<TextBlock
17+
Margin="0,0,0,8"
18+
Text="Hello from secondary app"
19+
TextAlignment="Center" />
20+
<Button
21+
HorizontalAlignment="Center"
22+
Click="CloseApp"
23+
Content="Close me" />
24+
</StackPanel>
25+
</Grid>
26+
</Page>

samples/TrayIconFlyout.Uwp.Sample.TrayHost/MainPage.xaml.cs renamed to samples/TrayIconFlyout.Uwp.Sample.SecondaryApp/MainPage.xaml.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// Copyright (c) 0x5BFA. All rights reserved.
1+
// Copyright (c) 0x5BFA. All rights reserved.
22
// Licensed under the MIT license.
33

4+
using Windows.ApplicationModel.Core;
45
using Windows.UI.Xaml.Controls;
56

67
namespace U5BFA.Libraries
@@ -11,5 +12,10 @@ public MainPage()
1112
{
1213
InitializeComponent();
1314
}
15+
16+
private void CloseApp(object sender, Windows.UI.Xaml.RoutedEventArgs e)
17+
{
18+
CoreApplication.Exit();
19+
}
1420
}
1521
}

samples/TrayIconFlyout.Uwp.Sample.SecondaryApp/MainPage2.xaml

Lines changed: 0 additions & 26 deletions
This file was deleted.

samples/TrayIconFlyout.Uwp.Sample.SecondaryApp/MainPage2.xaml.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,38 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<OutputType>WinExe</OutputType>
4-
<TargetFramework>net9.0-windows10.0.26100.0</TargetFramework>
5-
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
6-
<Nullable>enable</Nullable>
7-
<UseUwp>true</UseUwp>
8-
<Platforms>x86;x64;arm64</Platforms>
9-
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
10-
<DefaultLanguage>en-US</DefaultLanguage>
11-
<PublishAot>true</PublishAot>
12-
<PublishProfile>win-$(Platform).pubxml</PublishProfile>
13-
<DisableRuntimeMarshalling>true</DisableRuntimeMarshalling>
14-
</PropertyGroup>
2+
3+
<PropertyGroup>
154

16-
<ItemGroup>
17-
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.183" PrivateAssets="all" />
18-
<PackageReference Include="Microsoft.UI.Xaml" Version="2.8.7" />
19-
</ItemGroup>
5+
<OutputType>WinExe</OutputType>
6+
<TargetFramework>net9.0-windows10.0.26100.0</TargetFramework>
7+
8+
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
9+
<Platforms>x86;x64;arm64</Platforms>
10+
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
11+
<PublishProfile>win-$(Platform).pubxml</PublishProfile>
12+
<RootNamespace>U5BFA.Libraries</RootNamespace>
13+
<Nullable>enable</Nullable>
14+
<PublishAot>true</PublishAot>
15+
<DisableRuntimeMarshalling>true</DisableRuntimeMarshalling>
16+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
17+
<LangVersion>preview</LangVersion>
18+
<ApplicationManifest>app.manifest</ApplicationManifest>
19+
<EnableMsixTooling>true</EnableMsixTooling>
2020

21-
<ItemGroup>
22-
<Page Remove="App2.xaml" />
23-
</ItemGroup>
24-
<ItemGroup>
25-
<ApplicationDefinition Include="App2.xaml" />
26-
</ItemGroup>
27-
</Project>
21+
<UseUwp>true</UseUwp>
22+
<UseUwpTools>true</UseUwpTools>
23+
<DisableEmbeddedXbf>false</DisableEmbeddedXbf>
24+
<DefaultLanguage>en-US</DefaultLanguage>
25+
26+
</PropertyGroup>
27+
28+
<ItemGroup>
29+
<Page Remove="App2.xaml" />
30+
<ApplicationDefinition Include="App2.xaml" />
31+
</ItemGroup>
32+
33+
<ItemGroup>
34+
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.183" PrivateAssets="all" />
35+
<PackageReference Include="Microsoft.UI.Xaml" Version="2.8.7" />
36+
</ItemGroup>
37+
38+
</Project>

0 commit comments

Comments
 (0)