Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/Wpf.Ui/Controls/ClientAreaBorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
#nullable enable

using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shell;
using Wpf.Ui.Appearance;
using Wpf.Ui.Controls.Interfaces;
using Wpf.Ui.Dpi;
using Wpf.Ui.Interop;
using Size = System.Windows.Size;

namespace Wpf.Ui.Controls;
Expand Down Expand Up @@ -78,7 +80,7 @@ public Thickness PaddedBorderThickness
/// <summary>
/// If you use a <see cref="WindowChrome"/> to extend the client area of a window to the non-client area, you need to handle the edge margin issue when the window is maximized.
/// Use this property to get the correct margin value when the window is maximized, so that when the window is maximized, the client area can completely cover the screen client area by no less than a single pixel at any DPI.
/// The<see cref="Interop.User32.GetSystemMetrics"/> method cannot obtain this value directly.
/// The<see cref="User32.GetSystemMetrics"/> method cannot obtain this value directly.
/// </summary>
public Thickness WindowChromeNonClientFrameThickness => _windowChromeNonClientFrameThickness ??= new Thickness(
ResizeFrameBorderThickness.Left + PaddedBorderThickness.Left,
Expand Down Expand Up @@ -110,6 +112,7 @@ protected override void OnVisualParentChanged(DependencyObject oldParent)
if (_oldWindow is { } oldWindow)
{
oldWindow.StateChanged -= OnWindowStateChanged;
oldWindow.Closing -= OnWindowClosing;
}

var newWindow = (Window?)Window.GetWindow(this);
Expand All @@ -118,13 +121,19 @@ protected override void OnVisualParentChanged(DependencyObject oldParent)
{
newWindow.StateChanged -= OnWindowStateChanged; // Unsafe
newWindow.StateChanged += OnWindowStateChanged;
newWindow.Closing += OnWindowClosing;
}

_oldWindow = newWindow;

ApplyDefaultWindowBorder();
}

private void OnWindowClosing(object? sender, CancelEventArgs e)
{
Appearance.Theme.Changed -= OnThemeChanged;
if (_oldWindow != null)
_oldWindow.Closing -= OnWindowClosing;
}
private void OnWindowStateChanged(object? sender, EventArgs e)
{
if (sender is not Window window)
Expand Down
2 changes: 1 addition & 1 deletion src/Wpf.Ui/Controls/TitleBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ private void CloseWindow()

return;
}

Appearance.Theme.Changed -= OnThemeChanged;
ParentWindow.Close();
}

Expand Down