Skip to content
Open
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
42 changes: 24 additions & 18 deletions src/Wpf.Ui/Controls/FluentWindow/FluentWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

using System.Runtime.InteropServices;
using System.Windows.Shell;
using Wpf.Ui.Appearance;
using Wpf.Ui.Interop;
Expand Down Expand Up @@ -295,26 +294,33 @@ protected virtual void SetWindowChrome()
{
try
{
if (Utilities.IsCompositionEnabled)
bool canSetBorderMargins = Utilities.IsOSWindows11_24H2OrNewer;

Thickness glassFrameThickness = WindowBackdropType switch
{
WindowBackdropType.None when canSetBorderMargins => new Thickness(0),
WindowBackdropType.None => new Thickness(1),
_ => new Thickness(-1)
};

WindowChrome.SetWindowChrome(
this,
new WindowChrome
{
CaptionHeight = 0,
CornerRadius = default,
GlassFrameThickness = glassFrameThickness,
ResizeBorderThickness = ResizeMode == ResizeMode.NoResize ? default : new Thickness(4),
UseAeroCaptionButtons = false
}
);

if (canSetBorderMargins && WindowBackdropType == WindowBackdropType.None)
{
WindowChrome.SetWindowChrome(
this,
new WindowChrome
{
CaptionHeight = 0,
CornerRadius = default,
GlassFrameThickness =
WindowBackdropType == WindowBackdropType.None
? new Thickness(0.00001)
: new Thickness(-1), // 0.00001 so there's no glass frame drawn around the window, but the border is still drawn.
ResizeBorderThickness =
ResizeMode == ResizeMode.NoResize ? default : new Thickness(4),
UseAeroCaptionButtons = false,
}
);
UnsafeNativeMethods.SetBorderMargins(this, new Thickness(1));
}
}
catch (COMException)
catch
{
// Ignored.
}
Expand Down
23 changes: 23 additions & 0 deletions src/Wpf.Ui/Interop/UnsafeNativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,29 @@ public static bool RemoveWindowTitlebarContents(IntPtr handle)
return result.ToInt64() > 0;
}

public static void SetBorderMargins(Window window, Thickness thickness)
{
if (GetHandle(window, out IntPtr windowHandle))
{
FRAME_MARGIN frameMargin = new()
{
bottom = (short)thickness.Bottom,
left = (short)thickness.Left,
top = (short)thickness.Top,
right = (short)thickness.Right
};

unsafe
{
PInvoke.DwmSetWindowAttribute(
new HWND(windowHandle),
DWMWINDOWATTRIBUTE.DWMWA_BORDER_MARGINS,
&frameMargin,
(uint)sizeof(FRAME_MARGIN));
}
}
}

/// <summary>
/// Tries to get currently selected Window accent color.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion src/Wpf.Ui/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ HTMINBUTTON
HTNOWHERE
HTRIGHT*
HTSYSMENU
HTTOP*
HTTOP*
FRAME_MARGIN
12 changes: 6 additions & 6 deletions src/Wpf.Ui/Win32/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,22 @@ internal sealed class Utilities
/// <summary>
/// Gets a value indicating whether the operating system version is greater than or equal to 10.0* (build 10240).
/// </summary>
public static bool IsOSWindows10OrNewer => _osVersion.Build >= 10240;
public static bool IsOSWindows10OrNewer => _osVersion is { Major: >= 10, Build: >= 10240 };

/// <summary>
/// Gets a value indicating whether the operating system version is greater than or equal to 10.0* (build 22000).
/// </summary>
public static bool IsOSWindows11OrNewer => _osVersion.Build >= 22000;
public static bool IsOSWindows11OrNewer => _osVersion is { Major: >= 10, Build: >= 22000 };

/// <summary>
/// Gets a value indicating whether the operating system version is greater than or equal to 10.0* (build 22523).
/// Gets a value indicating whether the operating system version is greater than or equal to 10.0* (build 26100).
/// </summary>
public static bool IsOSWindows11Insider1OrNewer => _osVersion.Build >= 22523;
public static bool IsOSWindows11_24H2OrNewer => _osVersion is { Major: >= 10, Build: >= 26100 };

/// <summary>
/// Gets a value indicating whether the operating system version is greater than or equal to 10.0* (build 22557).
/// Gets a value indicating whether the operating system version is greater than or equal to 10.0* (build 22523).
/// </summary>
public static bool IsOSWindows11Insider2OrNewer => _osVersion.Build >= 22557;
public static bool IsOSWindows11Insider1OrNewer => _osVersion is { Major: >= 10, Build: >= 22523 };

/// <summary>
/// Gets a value indicating whether Desktop Window Manager (DWM) composition is enabled.
Expand Down
Loading