Skip to content

[ WPF Gallery ] White Border Around Main Window on Windows 10 - After Commit d38f0fcc #701

@cubekon

Description

@cubekon

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions