Skip to content

Commit 8387974

Browse files
authored
Removed the minimize and maximize buttons from the Properties window when using AppWindow (#8245)
1 parent 4aea07a commit 8387974

File tree

10 files changed

+648
-46
lines changed

10 files changed

+648
-46
lines changed

src/Files/App.xaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@
5151

5252
<SolidColorBrush x:Key="RootBackgroundBrush" Color="Transparent" />
5353

54-
<StaticResource x:Key="PropertiesDialogRootBackgroundBrush" ResourceKey="RootBackgroundBrush" />
55-
5654
<StaticResource x:Key="SidebarContentBackgroundBrush" ResourceKey="LayerFillColorDefaultBrush" />
5755
<SolidColorBrush x:Key="TitlebarContentBackgroundBrush" Color="Transparent" />
5856
<SolidColorBrush x:Key="NavigationViewContentBackground" Color="Transparent" />
@@ -80,8 +78,6 @@
8078

8179
<SolidColorBrush x:Key="RootBackgroundBrush" Color="Transparent" />
8280

83-
<StaticResource x:Key="PropertiesDialogRootBackgroundBrush" ResourceKey="RootBackgroundBrush" />
84-
8581
<StaticResource x:Key="SidebarContentBackgroundBrush" ResourceKey="LayerFillColorDefaultBrush" />
8682
<SolidColorBrush x:Key="TitlebarContentBackgroundBrush" Color="Transparent" />
8783
<SolidColorBrush x:Key="NavigationViewContentBackground" Color="Transparent" />
@@ -119,8 +115,6 @@
119115

120116
<SolidColorBrush x:Key="RootBackgroundBrush" Color="Transparent" />
121117

122-
<StaticResource x:Key="PropertiesDialogRootBackgroundBrush" ResourceKey="RootBackgroundBrush" />
123-
124118
<StaticResource x:Key="SidebarContentBackgroundBrush" ResourceKey="LayerFillColorDefaultBrush" />
125119
<SolidColorBrush x:Key="TitlebarContentBackgroundBrush" Color="Transparent" />
126120
<SolidColorBrush x:Key="NavigationViewContentBackground" Color="#0F000000" />

src/Files/App.xaml.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ protected override async void OnLaunched(LaunchActivatedEventArgs e)
261261
}
262262
}
263263
}
264+
265+
WindowDecorationsHelper.RequestWindowDecorationsAccess();
264266
}
265267

266268
protected override async void OnFileActivated(FileActivatedEventArgs e)
@@ -293,6 +295,8 @@ protected override async void OnFileActivated(FileActivatedEventArgs e)
293295
// Ensure the current window is active
294296
Window.Current.Activate();
295297
Window.Current.CoreWindow.Activated += CoreWindow_Activated;
298+
299+
WindowDecorationsHelper.RequestWindowDecorationsAccess();
296300
}
297301

298302
private Frame EnsureWindowIsInitialized()
@@ -482,6 +486,8 @@ async Task PerformNavigation(string payload, string selectItem = null)
482486
// Ensure the current window is active.
483487
Window.Current.Activate();
484488
Window.Current.CoreWindow.Activated += CoreWindow_Activated;
489+
490+
WindowDecorationsHelper.RequestWindowDecorationsAccess();
485491
}
486492

487493
private void TryEnablePrelaunch()
@@ -678,4 +684,4 @@ public static async void CloseApp()
678684
}
679685
}
680686
}
681-
}
687+
}

src/Files/Files.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@
200200
<Compile Include="Helpers\ItemListDisplayHelpers\GroupingHelper.cs" />
201201
<Compile Include="Helpers\StorageItemIconHelpers.cs" />
202202
<Compile Include="Helpers\StorageSenseHelper.cs" />
203+
<Compile Include="Helpers\WindowDecorationsHelper.cs" />
203204
<Compile Include="Helpers\UniversalLogWriter.cs" />
204205
<Compile Include="Helpers\SaveImageToFile.cs" />
205206
<Compile Include="Filesystem\FolderHelpers.cs" />
@@ -544,6 +545,7 @@
544545
<Compile Include="ViewModels\Widgets\IWidgetItemModel.cs" />
545546
<Compile Include="ViewModels\Widgets\WidgetsListControlItemViewModel.cs" />
546547
<Compile Include="ViewModels\Widgets\WidgetsListControlViewModel.cs" />
548+
<Compile Include="Views\Brushes\MicaBrush.cs" />
547549
<Compile Include="Views\ColumnParam.cs" />
548550
<Compile Include="Views\ColumnShellPage.xaml.cs">
549551
<DependentUpon>ColumnShellPage.xaml</DependentUpon>

src/Files/Helpers/FilePropertiesHelpers.cs

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
using Windows.Foundation.Metadata;
1010
using Windows.UI.Core;
1111
using Windows.UI.ViewManagement;
12+
using Windows.UI.WindowManagement;
13+
using Windows.UI.WindowManagement.Preview;
1214
using Windows.UI.Xaml;
1315
using Windows.UI.Xaml.Controls;
16+
using Windows.UI.Xaml.Hosting;
1417
using Windows.UI.Xaml.Media.Animation;
1518
using static Files.Views.Properties;
1619

@@ -55,33 +58,61 @@ public static async Task OpenPropertiesWindowAsync(object item, IShellPage assoc
5558

5659
if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8))
5760
{
58-
CoreApplicationView newWindow = CoreApplication.CreateNewView();
59-
ApplicationView newView = null;
60-
61-
await newWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
61+
if (WindowDecorationsHelper.IsWindowDecorationsAllowed)
6262
{
63+
AppWindow appWindow = await AppWindow.TryCreateAsync();
64+
6365
Frame frame = new Frame();
6466
frame.Navigate(typeof(Properties), new PropertiesPageNavigationArguments()
6567
{
6668
Item = item,
6769
AppInstanceArgument = associatedInstance
6870
}, new SuppressNavigationTransitionInfo());
69-
Window.Current.Content = frame;
70-
Window.Current.Activate();
71+
ElementCompositionPreview.SetAppWindowContent(appWindow, frame);
72+
(frame.Content as Properties).appWindow = appWindow;
7173

72-
newView = ApplicationView.GetForCurrentView();
73-
newWindow.TitleBar.ExtendViewIntoTitleBar = true;
74-
newView.Title = "PropertiesTitle".GetLocalized();
75-
newView.PersistedStateId = "Properties";
76-
newView.SetPreferredMinSize(new Size(460, 550));
74+
appWindow.TitleBar.ExtendsContentIntoTitleBar = true;
75+
appWindow.Title = "PropertiesTitle".GetLocalized();
76+
appWindow.PersistedStateId = "Properties";
77+
WindowManagementPreview.SetPreferredMinSize(appWindow, new Size(460, 550));
7778

78-
bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newView.Id);
79-
if (viewShown && newView != null)
79+
bool windowShown = await appWindow.TryShowAsync();
80+
if (windowShown)
8081
{
8182
// Set window size again here as sometimes it's not resized in the page Loaded event
82-
newView.TryResizeView(new Size(460, 550));
83+
appWindow.RequestSize(new Size(460, 550));
8384
}
84-
});
85+
}
86+
else
87+
{
88+
CoreApplicationView newWindow = CoreApplication.CreateNewView();
89+
ApplicationView newView = null;
90+
91+
await newWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
92+
{
93+
Frame frame = new Frame();
94+
frame.Navigate(typeof(Properties), new PropertiesPageNavigationArguments()
95+
{
96+
Item = item,
97+
AppInstanceArgument = associatedInstance
98+
}, new SuppressNavigationTransitionInfo());
99+
Window.Current.Content = frame;
100+
Window.Current.Activate();
101+
102+
newView = ApplicationView.GetForCurrentView();
103+
newWindow.TitleBar.ExtendViewIntoTitleBar = true;
104+
newView.Title = "PropertiesTitle".GetLocalized();
105+
newView.PersistedStateId = "Properties";
106+
newView.SetPreferredMinSize(new Size(460, 550));
107+
108+
bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newView.Id);
109+
if (viewShown && newView != null)
110+
{
111+
// Set window size again here as sometimes it's not resized in the page Loaded event
112+
newView.TryResizeView(new Size(460, 550));
113+
}
114+
});
115+
}
85116
}
86117
else
87118
{
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using Windows.ApplicationModel;
3+
using Windows.Foundation.Metadata;
4+
5+
namespace Files.Helpers
6+
{
7+
public static class WindowDecorationsHelper
8+
{
9+
public static bool IsWindowDecorationsAllowed { get; private set; }
10+
11+
public static void RequestWindowDecorationsAccess()
12+
{
13+
bool canSetAppWindowTitlebarVisibility = ApiInformation.IsMethodPresent("Windows.UI.WindowManagement.AppWindowTitleBar", "SetPreferredVisibility");
14+
15+
if (canSetAppWindowTitlebarVisibility)
16+
{
17+
string attestation = $"{Package.Current.Id.PublisherId} has registered their use of com.microsoft.windows.windowdecorations with Microsoft and agrees to the terms of use.";
18+
19+
string token = Package.Current.Id.Name switch
20+
{
21+
"Files" => "xnYLj99c3vN9jFCZiDC6Rg==",
22+
"FilesDev" => "Yoz9y1X66micskUKhFrJ5A==",
23+
"49306atecsolution.FilesUWP" => "+cyyj4JZUyZrBQ2eqDQGeA==",
24+
_ => String.Empty,
25+
};
26+
27+
LimitedAccessFeatureRequestResult accessResult = LimitedAccessFeatures.TryUnlockFeature("com.microsoft.windows.windowdecorations", token, attestation);
28+
if (accessResult.Status == LimitedAccessFeatureStatus.Available)
29+
{
30+
IsWindowDecorationsAllowed = true;
31+
}
32+
else
33+
{
34+
IsWindowDecorationsAllowed = false;
35+
}
36+
}
37+
else
38+
{
39+
IsWindowDecorationsAllowed = false;
40+
}
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)