From 9080158ba8d496501146d1167aae910898eff9af Mon Sep 17 00:00:00 2001
From: Matt <97983689+bluepilledgreat@users.noreply.github.com>
Date: Thu, 24 Oct 2024 20:27:56 +0100
Subject: [PATCH] improve clientareaborder (#7)
* improve clientareaborder
* update comments
---
src/Wpf.Ui/Controls/ClientAreaBorder.cs | 37 +++++++++++++++++++------
src/Wpf.Ui/Controls/UiWindow.cs | 32 +++++++++++++++++++++
2 files changed, 61 insertions(+), 8 deletions(-)
diff --git a/src/Wpf.Ui/Controls/ClientAreaBorder.cs b/src/Wpf.Ui/Controls/ClientAreaBorder.cs
index d15431069..335b117a9 100644
--- a/src/Wpf.Ui/Controls/ClientAreaBorder.cs
+++ b/src/Wpf.Ui/Controls/ClientAreaBorder.cs
@@ -24,8 +24,6 @@ namespace Wpf.Ui.Controls;
///
public class ClientAreaBorder : System.Windows.Controls.Border, IThemeControl
{
- private bool _borderBrushApplied = false;
-
private const int SM_CXFRAME = 32;
private const int SM_CYFRAME = 33;
@@ -96,9 +94,6 @@ private void OnThemeChanged(ThemeType currentTheme, Color systemAccent)
{
Theme = currentTheme;
- if (!_borderBrushApplied || _oldWindow == null)
- return;
-
ApplyDefaultWindowBorder();
}
@@ -140,14 +135,40 @@ private void OnWindowStateChanged(object? sender, EventArgs e)
private void ApplyDefaultWindowBorder()
{
if (Win32.Utilities.IsOSWindows11OrNewer || _oldWindow == null)
+ {
+ ResetDefaultWindowBorder(_oldWindow);
return;
+ }
+
+ ThemeType theme = Theme;
- _borderBrushApplied = true;
+ if (_oldWindow is UiWindow uiWindow)
+ {
+ if (!uiWindow.DefaultBorderEnabled)
+ {
+ ResetDefaultWindowBorder(uiWindow);
+ return;
+ }
+
+ if (uiWindow.DefaultBorderThemeOverwrite != ThemeType.Unknown)
+ theme = uiWindow.DefaultBorderThemeOverwrite;
+ }
// SystemParameters.WindowGlassBrush
- _oldWindow.BorderThickness = new Thickness(1);
- _oldWindow.BorderBrush = new SolidColorBrush(Theme == ThemeType.Light ? Color.FromArgb(0xFF, 0x7A, 0x7A, 0x7A) : Color.FromArgb(0xFF, 0x3A, 0x3A, 0x3A));
+ Brush brush = new SolidColorBrush(theme == ThemeType.Light ? Color.FromArgb(255, 200, 200, 200) : Color.FromArgb(255, 58, 58, 58));
+
+ BorderThickness = new Thickness(1);
+ BorderBrush = brush;
+ }
+
+ private void ResetDefaultWindowBorder(Window? window)
+ {
+ if (window == null)
+ return;
+
+ BorderBrush = window.BorderBrush;
+ BorderThickness = window.BorderThickness;
}
private (double factorX, double factorY) GetDpi()
diff --git a/src/Wpf.Ui/Controls/UiWindow.cs b/src/Wpf.Ui/Controls/UiWindow.cs
index 1b3af2f50..5b0ad49ab 100644
--- a/src/Wpf.Ui/Controls/UiWindow.cs
+++ b/src/Wpf.Ui/Controls/UiWindow.cs
@@ -73,6 +73,20 @@ protected HwndSource HwndSource
nameof(WindowBackdropType),
typeof(BackgroundType), typeof(UiWindow), new PropertyMetadata(BackgroundType.None, OnBackdropTypeChanged));
+ ///
+ /// Property for .
+ ///
+ public static readonly DependencyProperty DefaultBorderEnabledProperty = DependencyProperty.Register(
+ nameof(DefaultBorderEnabled),
+ typeof(bool), typeof(UiWindow), new PropertyMetadata(true));
+
+ ///
+ /// Property for .
+ ///
+ public static readonly DependencyProperty DefaultBorderThemeOverwriteProperty = DependencyProperty.Register(
+ nameof(DefaultBorderThemeOverwrite),
+ typeof(ThemeType), typeof(UiWindow), new PropertyMetadata(ThemeType.Unknown));
+
///
/// Gets or sets a value determining whether the content should be extended into title bar.
///
@@ -100,6 +114,24 @@ public BackgroundType WindowBackdropType
set => SetValue(WindowBackdropTypeProperty, value);
}
+ ///
+ /// Should apply the default border to windows.
+ ///
+ public bool DefaultBorderEnabled
+ {
+ get => (bool)GetValue(DefaultBorderEnabledProperty);
+ set => SetValue(DefaultBorderEnabledProperty, value);
+ }
+
+ ///
+ /// Overwrites the default border theme value.
+ ///
+ public ThemeType DefaultBorderThemeOverwrite
+ {
+ get => (ThemeType)GetValue(DefaultBorderThemeOverwriteProperty);
+ set => SetValue(DefaultBorderThemeOverwriteProperty, value);
+ }
+
#endregion Public properties
#region Constructors