Skip to content

Commit

Permalink
improve clientareaborder (#7)
Browse files Browse the repository at this point in the history
* improve clientareaborder

* update comments
  • Loading branch information
bluepilledgreat authored Oct 24, 2024
1 parent c4c58c5 commit 9080158
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 8 deletions.
37 changes: 29 additions & 8 deletions src/Wpf.Ui/Controls/ClientAreaBorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ namespace Wpf.Ui.Controls;
/// </summary>
public class ClientAreaBorder : System.Windows.Controls.Border, IThemeControl
{
private bool _borderBrushApplied = false;

private const int SM_CXFRAME = 32;

private const int SM_CYFRAME = 33;
Expand Down Expand Up @@ -96,9 +94,6 @@ private void OnThemeChanged(ThemeType currentTheme, Color systemAccent)
{
Theme = currentTheme;

if (!_borderBrushApplied || _oldWindow == null)
return;

ApplyDefaultWindowBorder();
}

Expand Down Expand Up @@ -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()
Expand Down
32 changes: 32 additions & 0 deletions src/Wpf.Ui/Controls/UiWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ protected HwndSource HwndSource
nameof(WindowBackdropType),
typeof(BackgroundType), typeof(UiWindow), new PropertyMetadata(BackgroundType.None, OnBackdropTypeChanged));

/// <summary>
/// Property for <see cref="DefaultBorderEnabled"/>.
/// </summary>
public static readonly DependencyProperty DefaultBorderEnabledProperty = DependencyProperty.Register(
nameof(DefaultBorderEnabled),
typeof(bool), typeof(UiWindow), new PropertyMetadata(true));

/// <summary>
/// Property for <see cref="DefaultBorderThemeOverwrite"/>.
/// </summary>
public static readonly DependencyProperty DefaultBorderThemeOverwriteProperty = DependencyProperty.Register(
nameof(DefaultBorderThemeOverwrite),
typeof(ThemeType), typeof(UiWindow), new PropertyMetadata(ThemeType.Unknown));

/// <summary>
/// Gets or sets a value determining whether the <see cref="Window"/> content should be extended into title bar.
/// </summary>
Expand Down Expand Up @@ -100,6 +114,24 @@ public BackgroundType WindowBackdropType
set => SetValue(WindowBackdropTypeProperty, value);
}

/// <summary>
/// Should apply the default border to windows.
/// </summary>
public bool DefaultBorderEnabled
{
get => (bool)GetValue(DefaultBorderEnabledProperty);
set => SetValue(DefaultBorderEnabledProperty, value);
}

/// <summary>
/// Overwrites the default border theme value.
/// </summary>
public ThemeType DefaultBorderThemeOverwrite
{
get => (ThemeType)GetValue(DefaultBorderThemeOverwriteProperty);
set => SetValue(DefaultBorderThemeOverwriteProperty, value);
}

#endregion Public properties

#region Constructors
Expand Down

0 comments on commit 9080158

Please sign in to comment.