更新整理
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
|
||||
|
||||
|
||||
using WPFluent.Appearance;
|
||||
using WPFluent.Hardware;
|
||||
|
||||
using System.Windows.Shell;
|
||||
|
||||
using WPFluent.Appearance;
|
||||
|
||||
using WPFluent.Hardware;
|
||||
|
||||
using Size = System.Windows.Size;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
@@ -45,7 +47,7 @@ public class ClientAreaBorder : System.Windows.Controls.Border, IThemeControl
|
||||
|
||||
private void ApplyDefaultWindowBorder()
|
||||
{
|
||||
if(Win32.Utilities.IsOSWindows11OrNewer || _oldWindow == null)
|
||||
if (Win32.Utilities.IsOSWindows11OrNewer || _oldWindow == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -65,7 +67,7 @@ public class ClientAreaBorder : System.Windows.Controls.Border, IThemeControl
|
||||
|
||||
private (double FactorX, double FactorY) GetDpi()
|
||||
{
|
||||
if(PresentationSource.FromVisual(this) is { } source)
|
||||
if (PresentationSource.FromVisual(this) is { } source)
|
||||
{
|
||||
return (
|
||||
source.CompositionTarget.TransformToDevice.M11, // Possible null reference
|
||||
@@ -82,7 +84,7 @@ public class ClientAreaBorder : System.Windows.Controls.Border, IThemeControl
|
||||
{
|
||||
ApplicationTheme = currentApplicationTheme;
|
||||
|
||||
if(!_borderBrushApplied || _oldWindow == null)
|
||||
if (!_borderBrushApplied || _oldWindow == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -93,7 +95,7 @@ public class ClientAreaBorder : System.Windows.Controls.Border, IThemeControl
|
||||
private void OnWindowClosing(object? sender, CancelEventArgs e)
|
||||
{
|
||||
Appearance.ApplicationThemeManager.Changed -= OnThemeChanged;
|
||||
if(_oldWindow != null)
|
||||
if (_oldWindow != null)
|
||||
{
|
||||
_oldWindow.Closing -= OnWindowClosing;
|
||||
}
|
||||
@@ -101,7 +103,7 @@ public class ClientAreaBorder : System.Windows.Controls.Border, IThemeControl
|
||||
|
||||
private void OnWindowStateChanged(object? sender, EventArgs e)
|
||||
{
|
||||
if(sender is not System.Windows.Window window)
|
||||
if (sender is not System.Windows.Window window)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -116,7 +118,7 @@ public class ClientAreaBorder : System.Windows.Controls.Border, IThemeControl
|
||||
{
|
||||
base.OnVisualParentChanged(oldParent);
|
||||
|
||||
if(_oldWindow is { } oldWindow)
|
||||
if (_oldWindow is { } oldWindow)
|
||||
{
|
||||
oldWindow.StateChanged -= OnWindowStateChanged;
|
||||
oldWindow.Closing -= OnWindowClosing;
|
||||
@@ -124,7 +126,7 @@ public class ClientAreaBorder : System.Windows.Controls.Border, IThemeControl
|
||||
|
||||
var newWindow = System.Windows.Window.GetWindow(this);
|
||||
|
||||
if(newWindow is not null)
|
||||
if (newWindow is not null)
|
||||
{
|
||||
newWindow.StateChanged -= OnWindowStateChanged; // Unsafe
|
||||
newWindow.StateChanged += OnWindowStateChanged;
|
||||
@@ -138,35 +140,6 @@ public class ClientAreaBorder : System.Windows.Controls.Border, IThemeControl
|
||||
|
||||
public ApplicationTheme ApplicationTheme { get; set; } = ApplicationTheme.Unknown;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the system value for the padded border thickness (<see cref="User32.SM.CXPADDEDBORDER"/>) in WPF units.
|
||||
/// </summary>
|
||||
public Thickness PaddedBorderThickness
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_paddedBorderThickness is not null)
|
||||
{
|
||||
return _paddedBorderThickness.Value;
|
||||
}
|
||||
|
||||
var paddedBorder = Interop.User32.GetSystemMetrics(Interop.User32.SM.CXPADDEDBORDER);
|
||||
|
||||
(double factorX, double factorY) = GetDpi();
|
||||
|
||||
var frameSize = new Size(paddedBorder, paddedBorder);
|
||||
var frameSizeInDips = new Size(frameSize.Width / factorX, frameSize.Height / factorY);
|
||||
|
||||
_paddedBorderThickness = new Thickness(
|
||||
frameSizeInDips.Width,
|
||||
frameSizeInDips.Height,
|
||||
frameSizeInDips.Width,
|
||||
frameSizeInDips.Height);
|
||||
|
||||
return _paddedBorderThickness.Value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the system <see cref="User32.SM.CXFRAME"/> and <see cref="User32.SM.CYFRAME"/> values in WPF units.
|
||||
/// </summary>
|
||||
@@ -187,8 +160,8 @@ public class ClientAreaBorder : System.Windows.Controls.Border, IThemeControl
|
||||
/// cannot obtain this value directly.
|
||||
/// </remarks>
|
||||
public Thickness WindowChromeNonClientFrameThickness => _windowChromeNonClientFrameThickness ??= new Thickness(
|
||||
ClientAreaBorder.ResizeFrameBorderThickness.Left + PaddedBorderThickness.Left,
|
||||
ClientAreaBorder.ResizeFrameBorderThickness.Top + PaddedBorderThickness.Top,
|
||||
ClientAreaBorder.ResizeFrameBorderThickness.Right + PaddedBorderThickness.Right,
|
||||
ClientAreaBorder.ResizeFrameBorderThickness.Bottom + PaddedBorderThickness.Bottom);
|
||||
ClientAreaBorder.ResizeFrameBorderThickness.Left,
|
||||
ClientAreaBorder.ResizeFrameBorderThickness.Top,
|
||||
ClientAreaBorder.ResizeFrameBorderThickness.Right,
|
||||
ClientAreaBorder.ResizeFrameBorderThickness.Bottom);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user