-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Open
Description
Short Description:
Since commit d38f0fcc
, a white border appears around the main window in the WPF Gallery application, but only on Windows 10.
Cause:
The root cause seems to be a different rendering behavior of WindowChrome
between Windows 10 and Windows 11.
Maybe there is a connection with this ticket: The WindowChrome class needs to be updated & fixed #3887
Proposed Fix:
Force NonClientFrameEdges = NonClientFrameEdges.None
during initialization and updates:
WindowChrome.SetWindowChrome(
this,
new WindowChrome
{
CaptionHeight = 50,
CornerRadius = new CornerRadius(12),
GlassFrameThickness = new Thickness(-1),
ResizeBorderThickness = ResizeMode == ResizeMode.NoResize ? default : new Thickness(4),
UseAeroCaptionButtons = true,
NonClientFrameEdges = NonClientFrameEdges.None // <-- For windows 10 only
}
);
And in UpdateMainWindowVisuals()
:
var wc = WindowChrome.GetWindowChrome(this);
if (wc is not null)
{
wc.NonClientFrameEdges = NonClientFrameEdges.None; // <-- For windows 10 only
}
Additional Suggestion:
Enable Immersive Dark Mode to prevent flashing white backgrounds during window resize:
[DllImport("dwmapi.dll")]
private static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
private const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
private void ApplyWindowDarkMode()
{
IntPtr hwnd = new WindowInteropHelper(this).Handle;
int darkMode = 1;
DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE, ref darkMode, sizeof(int));
}
this.Loaded += (s, e) => ApplyWindowDarkMode();
Environment:
- Windows 10
- .NET version: 9 and 10
- WPF Gallery latest main branch
Metadata
Metadata
Assignees
Labels
No labels