Skip to content

Commit

Permalink
现在 Win32 窗口最小化不会出错了
Browse files Browse the repository at this point in the history
  • Loading branch information
wherewhere committed Nov 6, 2023
1 parent 3f4267c commit 2ddf59c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
5 changes: 0 additions & 5 deletions CoreAppUWP/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
<!-- Breakpoints -->
<x:Double x:Key="Breakpoint640Plus">641</x:Double>

<Thickness x:Key="PageHeaderDefaultPadding">0</Thickness>
<Thickness x:Key="PageHeaderMinimalPadding">-4,0,12,0</Thickness>

<Thickness x:Key="ControlElementScreenshotModePadding">67</Thickness>

<!-- L-Pattern Overwriting resources -->
<Thickness x:Key="NavigationViewContentMargin">0,48,0,0</Thickness>
<Thickness x:Key="NavigationViewContentGridBorderThickness">1,1,0,0</Thickness>
Expand Down
5 changes: 2 additions & 3 deletions CoreAppUWP/Controls/DesktopWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public static Task<DesktopWindow> CreateAsync(Action<DesktopWindowXamlSource> la
DesktopWindowXamlSource source = new();
source.Initialize(window.Id);
DesktopChildSiteBridge bridge = source.SiteBridge;
bridge.ResizePolicy = ContentSizePolicy.ResizeContentToParentWindow;
window.Changed += (sender, args) =>
{
if (args.DidPresenterChange)
Expand All @@ -114,7 +115,6 @@ public static Task<DesktopWindow> CreateAsync(Action<DesktopWindowXamlSource> la
}
};
bridge.Show();
bridge.ResizePolicy = ContentSizePolicy.ResizeContentToParentWindow;
launched(source);
hook.EndHook();
DesktopWindow desktopWindow = new()
Expand Down Expand Up @@ -153,11 +153,11 @@ public static Task<DesktopWindow> CreateAsync(DispatcherQueue dispatcherQueue, A
HookWindowingModel hook = new();
hook.StartHook();
AppWindow window = AppWindow.Create();
window.Destroying += (sender, args) => dispatcherQueue.EnqueueEventLoopExit();
window.AssociateWithDispatcherQueue(dispatcherQueue);
DesktopWindowXamlSource source = new();
source.Initialize(window.Id);
DesktopChildSiteBridge bridge = source.SiteBridge;
bridge.ResizePolicy = ContentSizePolicy.ResizeContentToParentWindow;
window.Changed += (sender, args) =>
{
if (args.DidPresenterChange)
Expand All @@ -167,7 +167,6 @@ public static Task<DesktopWindow> CreateAsync(DispatcherQueue dispatcherQueue, A
}
};
bridge.Show();
bridge.ResizePolicy = ContentSizePolicy.ResizeContentToParentWindow;
launched(source);
hook.EndHook();
DesktopWindow desktopWindow = new()
Expand Down
2 changes: 1 addition & 1 deletion CoreAppUWP/Pages/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ private void UpdateAppTitle(CoreApplicationViewTitleBar coreTitleBar)
private void UpdateAppTitle(AppWindow appWindow)
{
IntPtr hwnd = (IntPtr)appWindow.Id.Value;
RightPaddingColumn.Width = new GridLength(appWindow.TitleBar.RightInset.GetDisplayPixel(hwnd));
RightPaddingColumn.Width = new GridLength(Math.Max(0, appWindow.TitleBar.RightInset.GetDisplayPixel(hwnd)));
}

private void System_BackRequested(object sender, BackRequestedEventArgs e)
Expand Down
14 changes: 13 additions & 1 deletion CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:animatedvisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals"
xmlns:common="using:CoreAppUWP.Common"
xmlns:controls="using:CoreAppUWP.Controls"
xmlns:converters="using:CommunityToolkit.WinUI.UI.Converters"
xmlns:cwuc="using:CommunityToolkit.WinUI.UI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:interopservices="using:System.Runtime.InteropServices"
Expand All @@ -14,6 +15,9 @@
DataContext="{x:Bind Provider, Mode=OneWay}"
NavigationCacheMode="Enabled"
mc:Ignorable="d">
<Page.Resources>
<converters:BoolNegationConverter x:Key="BoolNegationConverter" />
</Page.Resources>
<Grid
x:Name="RootGrid"
Padding="20,20,0,0"
Expand Down Expand Up @@ -54,7 +58,7 @@
Description="Select Backdrop Type for Windows 11"
Header="Backdrop"
Icon="&#xE81E;">
<ComboBox SelectedIndex="{Binding SelectedBackdrop, Mode=TwoWay}">
<ComboBox SelectedIndex="{x:Bind Provider.SelectedBackdrop, Mode=TwoWay}">
<x:String>Mica</x:String>
<x:String>MicaAlt</x:String>
<x:String>Acrylic</x:String>
Expand Down Expand Up @@ -352,11 +356,19 @@
</controls:SettingExpander.Description>
<Grid Style="{StaticResource SettingExpanderContentGridStyle}">
<cwuc:MarkdownTextBlock
x:Name="AboutMarkdown"
HorizontalAlignment="Left"
x:Load="{x:Bind IsCoreWindow}"
Background="{ThemeResource SystemControlTransparentBrush}"
LinkClicked="MarkdownText_LinkClicked"
LinkForeground="{ThemeResource HyperlinkForeground}"
Text="{x:Bind Provider.AboutTextBlockText, Mode=OneWay}" />
<TextBlock
x:Name="AboutTextBlock"
HorizontalAlignment="Left"
x:Load="{x:Bind IsCoreWindow, Converter={StaticResource BoolNegationConverter}}"
Text="{x:Bind Provider.AboutTextBlockText, Mode=OneWay}"
TextWrapping="Wrap" />
</Grid>
</controls:SettingExpander>
</controls:SettingsGroup>
Expand Down
22 changes: 6 additions & 16 deletions CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ private async void Button_Click(object sender, RoutedEventArgs e)
SettingsHelper.LocalObject.Clear();
SettingsHelper.SetDefaultSettings();
if (Reset.Flyout is Flyout flyout_reset)
{
flyout_reset.Hide();
}
{ flyout_reset.Hide(); }
_ = Refresh(true);
break;
case "ExitPIP":
Expand All @@ -82,9 +80,7 @@ private async void Button_Click(object sender, RoutedEventArgs e)
_ = ApplicationView.GetForCurrentView().TryEnterViewModeAsync(ApplicationViewMode.Default);
}
else if (this.GetWindowForElement() is DesktopWindow desktopWindow)
{
desktopWindow.AppWindow.SetPresenter(AppWindowPresenterKind.Default);
}
{ desktopWindow.AppWindow.SetPresenter(AppWindowPresenterKind.Default); }
break;
case "EnterPIP":
if (IsCoreWindow)
Expand All @@ -93,17 +89,13 @@ private async void Button_Click(object sender, RoutedEventArgs e)
_ = ApplicationView.GetForCurrentView().TryEnterViewModeAsync(ApplicationViewMode.CompactOverlay);
}
else if (this.GetWindowForElement() is DesktopWindow desktopWindow)
{
desktopWindow.AppWindow.SetPresenter(AppWindowPresenterKind.CompactOverlay);
}
{ desktopWindow.AppWindow.SetPresenter(AppWindowPresenterKind.CompactOverlay); }
break;
case "NewWindow":
case "NewWindow" when IsCoreWindow:
_ = await WindowHelper.CreateWindowAsync(window =>
{
if (SettingsHelper.Get<bool>(SettingsHelper.IsExtendsTitleBar))
{
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
}
{ CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true; }
Frame _frame = new();
window.Content = _frame;
ThemeHelper.Initialize(window);
Expand All @@ -120,9 +112,7 @@ private async void Button_Click(object sender, RoutedEventArgs e)
}).ConfigureAwait(false);
if (AppWindowTitleBar.IsCustomizationSupported()
&& SettingsHelper.Get<bool>(SettingsHelper.IsExtendsTitleBar))
{
window.ExtendsContentIntoTitleBar = true;
}
{ window.ExtendsContentIntoTitleBar = true; }
ThemeHelper.Initialize(window);
BackdropHelper.SetBackdrop(window, SettingsHelper.Get<BackdropType>(SettingsHelper.SelectedBackdrop));
AppWindow appWindow = window.AppWindow;
Expand Down
8 changes: 6 additions & 2 deletions CoreAppUWP/ViewModels/SettingsPages/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public int SelectedTheme
}
}

public static int SelectedBackdrop
public int SelectedBackdrop
{
get => (int)SettingsHelper.Get<BackdropType>(SettingsHelper.SelectedBackdrop);
set
Expand All @@ -58,6 +58,7 @@ public static int SelectedBackdrop
BackdropType type = (BackdropType)value;
SettingsHelper.Set(SettingsHelper.SelectedBackdrop, type);
BackdropHelper.SetAllBackdrop(type);
RaisePropertyChangedEvent();
}
}
}
Expand Down Expand Up @@ -160,7 +161,10 @@ public async Task Refresh(bool reset)
{
if (reset)
{
RaisePropertyChangedEvent(nameof(SelectedTheme));
RaisePropertyChangedEvent(
nameof(SelectedTheme),
nameof(SelectedBackdrop),
nameof(IsExtendsTitleBar));
}
await GetAboutTextBlockTextAsync();
}
Expand Down

0 comments on commit 2ddf59c

Please sign in to comment.