File tree Expand file tree Collapse file tree 7 files changed +33
-23
lines changed
src/DotVast.HashTool.WinUI Expand file tree Collapse file tree 7 files changed +33
-23
lines changed Original file line number Diff line number Diff line change 6767 <PackageReference Include =" Serilog.Extensions.Hosting" Version =" 9.0.0" />
6868 <PackageReference Include =" Serilog.Sinks.File" Version =" 6.0.0" />
6969 <PackageReference Include =" System.IO.Hashing" Version =" 9.0.0" />
70- <PackageReference Include =" WinUIEx" Version =" 2.3.4" />
7170 </ItemGroup >
7271
7372 <ItemGroup >
Original file line number Diff line number Diff line change 1- <windowex : WindowEx
1+ <Window
22 x : Class =" DotVast.HashTool.WinUI.MainWindow"
33 xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4- xmlns : x =" http://schemas.microsoft.com/winfx/2006/xaml"
5- xmlns : windowex =" using:WinUIEx"
6- Width =" 840"
7- Height =" 540"
8- MinWidth =" 500"
9- MinHeight =" 300"
10- PersistenceId =" MainWindow" >
4+ xmlns : x =" http://schemas.microsoft.com/winfx/2006/xaml" >
5+ <!--
6+ Width="840"
7+ Height="540"
8+ MinWidth="500"
9+ MinHeight="300"
10+ PersistenceId="MainWindow"
11+ -->
1112 <Window .SystemBackdrop>
1213 <MicaBackdrop />
1314 </Window .SystemBackdrop>
14- </windowex : WindowEx >
15+ </Window >
Original file line number Diff line number Diff line change 22// Licensed under the MIT License.
33
44using Microsoft . Extensions . Logging ;
5-
6- using WinUIEx ;
5+ using Microsoft . UI . Windowing ;
6+ using Microsoft . UI . Xaml ;
77
88namespace DotVast . HashTool . WinUI ;
99
10- public sealed partial class MainWindow : WindowEx
10+ public sealed partial class MainWindow : Window
1111{
1212 private readonly ILogger < MainWindow > _logger = App . GetLogger < MainWindow > ( ) ;
1313
Original file line number Diff line number Diff line change 99using Microsoft . UI . Xaml ;
1010using Microsoft . Windows . AppLifecycle ;
1111
12- using WinUIEx ;
13-
1412namespace DotVast . HashTool . WinUI . Services ;
1513
1614public sealed class ActivationService (
@@ -32,19 +30,24 @@ public sealed class ActivationService(
3230
3331 public async Task ActivateAsync ( object activationArgs )
3432 {
33+ var mainWindow = App . MainWindow ;
34+
3535 // Set the MainWindow Content.
36- App . MainWindow . Content ??= App . GetService < ShellPage > ( ) ;
36+ mainWindow . Content ??= App . GetService < ShellPage > ( ) ;
3737
3838 // Execute tasks before activation.
3939 await InitializeAsync ( ) ;
4040
4141 // Handle activation via ActivationHandlers.
4242 await HandleActivationAsync ( activationArgs ) ;
4343
44- App . MainWindow . CenterOnScreen ( ) ;
44+ //TODO: https://github.com/microsoft/WindowsAppSDK/discussions/4710
45+ //App.MainWindow.CenterOnScreen();
46+ var scale = mainWindow . Content . XamlRoot . RasterizationScale ;
47+ mainWindow . AppWindow . ResizeClient ( new ( ( int ) ( 840 * scale ) , ( int ) ( 540 * scale ) ) ) ;
4548
4649 // Activate the MainWindow.
47- App . MainWindow . Activate ( ) ;
50+ mainWindow . Activate ( ) ;
4851
4952 // Execute tasks after activation.
5053 await StartupAsync ( ) ;
Original file line number Diff line number Diff line change 88using DotVast . HashTool . WinUI . Enums ;
99using DotVast . HashTool . WinUI . Helpers ;
1010
11+ using Microsoft . UI . Windowing ;
1112using Microsoft . UI . Xaml ;
1213
1314using WGAL = Windows . Globalization . ApplicationLanguages ;
@@ -30,7 +31,10 @@ public override Task StartupAsync()
3031 SetIsAlwaysOnTop ( ) ;
3132
3233 Debug . Assert ( ( App . MainWindow . Content as FrameworkElement ) ? . RequestedTheme == Theme . ToElementTheme ( ) ) ;
33- Debug . Assert ( App . MainWindow . IsAlwaysOnTop == IsAlwaysOnTop ) ;
34+ if ( App . MainWindow . AppWindow . Presenter is OverlappedPresenter presenter )
35+ {
36+ Debug . Assert ( presenter . IsAlwaysOnTop == IsAlwaysOnTop ) ;
37+ }
3438 Debug . Assert ( WGAL . PrimaryLanguageOverride == Language . ToTag ( ) ) ;
3539
3640 return Task . CompletedTask ;
@@ -54,7 +58,10 @@ public bool IsAlwaysOnTop
5458 }
5559 private void SetIsAlwaysOnTop ( )
5660 {
57- App . MainWindow . IsAlwaysOnTop = IsAlwaysOnTop ;
61+ if ( App . MainWindow . AppWindow . Presenter is OverlappedPresenter presenter )
62+ {
63+ presenter . IsAlwaysOnTop = IsAlwaysOnTop ;
64+ }
5865 }
5966 #endregion IsAlwaysOnTop
6067
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ private async Task PickAsync()
2828 FileOpenPicker picker = new ( ) ;
2929 picker . FileTypeFilter . Add ( "*" ) ;
3030
31- var hwnd = WinUIEx . HwndExtensions . GetActiveWindow ( ) ;
31+ var hwnd = WinRT . Interop . WindowNative . GetWindowHandle ( App . MainWindow ) ;
3232 WinRT . Interop . InitializeWithWindow . Initialize ( picker , hwnd ) ;
3333
3434 var result = await picker . PickMultipleFilesAsync ( ) ;
@@ -42,7 +42,7 @@ private async Task PickAsync()
4242 FolderPicker picker = new ( ) ;
4343 picker . FileTypeFilter . Add ( "*" ) ;
4444
45- var hwnd = WinUIEx . HwndExtensions . GetActiveWindow ( ) ;
45+ var hwnd = WinRT . Interop . WindowNative . GetWindowHandle ( App . MainWindow ) ;
4646 WinRT . Interop . InitializeWithWindow . Initialize ( picker , hwnd ) ;
4747
4848 var result = await picker . PickSingleFolderAsync ( ) ;
Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ private async Task SaveAsync()
110110 picker . FileTypeChoices . Add ( "Text" , [ ".txt" ] ) ;
111111 picker . FileTypeChoices . Add ( "JSON" , [ ".json" ] ) ;
112112
113- var hwnd = WinUIEx . HwndExtensions . GetActiveWindow ( ) ;
113+ var hwnd = WinRT . Interop . WindowNative . GetWindowHandle ( App . MainWindow ) ;
114114 WinRT . Interop . InitializeWithWindow . Initialize ( picker , hwnd ) ;
115115
116116 var file = await picker . PickSaveFileAsync ( ) ;
You can’t perform that action at this time.
0 commit comments