-
Notifications
You must be signed in to change notification settings - Fork 8k
/
Scenario4_CompactOverlay.xaml.cs
86 lines (77 loc) · 3.27 KB
/
Scenario4_CompactOverlay.xaml.cs
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
//*********************************************************
//
// 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.
//
//*********************************************************
using System;
using Windows.UI.ViewManagement;
using Windows.UI.WindowManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Hosting;
using Windows.UI.Xaml.Navigation;
namespace SDKTemplate
{
public sealed partial class Scenario4_CompactOverlay : Page
{
private AppWindow appWindow;
private Frame appWindowFrame = new Frame();
public Scenario4_CompactOverlay()
{
this.InitializeComponent();
}
protected override async void OnNavigatedFrom(NavigationEventArgs e)
{
if (appWindow != null)
{
await appWindow.CloseAsync();
}
}
private async void ShowWindowBtn_Click(object sender, RoutedEventArgs e)
{
// Is CompactOverlay supported for our main window?
// If so, it will be supported for a new window as well.
// If it isn't, it will not be supported for new windows either so we cannot proceed.
if (!ApplicationView.GetForCurrentView().IsViewModeSupported(ApplicationViewMode.CompactOverlay))
{
return;
}
showWindowBtn.IsEnabled = false;
if (appWindow == null)
{
// Create a new AppWindow
appWindow = await AppWindow.TryCreateAsync();
// Make sure we release the reference to this window, and release XAML resources, when it's closed
appWindow.Closed += delegate { appWindow = null; appWindowFrame.Content = null; };
// Is CompactOverlay supported for this AppWindow? If not, then stop.
if (appWindow.Presenter.IsPresentationSupported(AppWindowPresentationKind.CompactOverlay))
{
// Create a new frame for the window
// Navigate the frame to the CompactOverlay page inside it.
appWindowFrame.Navigate(typeof(SecondaryAppWindowPage));
// Attach the frame to the window
ElementCompositionPreview.SetAppWindowContent(appWindow, appWindowFrame);
// Let's set the title so that we can tell the windows apart
appWindow.Title = "CompactOverlay Window";
// Request the Presentation of the window to CompactOverlay
bool switched = appWindow.Presenter.RequestPresentation(AppWindowPresentationKind.CompactOverlay);
if (switched)
{
// If the request was satisfied, show the window
await appWindow.TryShowAsync();
}
}
}
else
{
await appWindow.TryShowAsync();
}
showWindowBtn.IsEnabled = true;
}
}
}