Skip to content

Commit a3214e8

Browse files
committed
refactor: 移除 WinUIEx
1 parent 3b607ae commit a3214e8

File tree

7 files changed

+33
-23
lines changed

7 files changed

+33
-23
lines changed

src/DotVast.HashTool.WinUI/DotVast.HashTool.WinUI.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
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>
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
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>

src/DotVast.HashTool.WinUI/MainWindow.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
// Licensed under the MIT License.
33

44
using Microsoft.Extensions.Logging;
5-
6-
using WinUIEx;
5+
using Microsoft.UI.Windowing;
6+
using Microsoft.UI.Xaml;
77

88
namespace 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

src/DotVast.HashTool.WinUI/Services/ActivationService.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
using Microsoft.UI.Xaml;
1010
using Microsoft.Windows.AppLifecycle;
1111

12-
using WinUIEx;
13-
1412
namespace DotVast.HashTool.WinUI.Services;
1513

1614
public 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();

src/DotVast.HashTool.WinUI/Services/Settings/AppearanceSettingsService.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using DotVast.HashTool.WinUI.Enums;
99
using DotVast.HashTool.WinUI.Helpers;
1010

11+
using Microsoft.UI.Windowing;
1112
using Microsoft.UI.Xaml;
1213

1314
using 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

src/DotVast.HashTool.WinUI/ViewModels/HomeViewModel.Commands.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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();

src/DotVast.HashTool.WinUI/ViewModels/TasksViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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();

0 commit comments

Comments
 (0)