microsoft / microsoft/WPF-Samples

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

Open
#701 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
5.7k
Forks
3.3k
Avg merge
12d 8h
Merged PRs (30d)
2

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the WPF Gallery main-window code where WindowChrome is initialized and inspect UpdateMainWindowVisuals(). Reproduce the white border and resize flashing on Windows 10, then verify the proposed NonClientFrameEdges and dark-mode behavior without regressing Windows 11.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop, operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.