wpfui icon indicating copy to clipboard operation
wpfui copied to clipboard

Part of title bar is still rendered when it should not

Open yagudron opened this issue 1 year ago • 17 comments

Describe the bug

I recently started using the library, and whilst working on Windows 10 machine everything looked as expected. When I moved my work to Windows 11, I noticed some part of the title bar is rendered, even when shouldn't. Attaching examples of that reproduced for the WPF UI Gallery. I have not yet found any workarounds to remove it in my app too.

To Reproduce

Start WPF UI Gallery or demo app.

Expected behavior

No additional elements in the title bar.

Screenshots

Windows 10: Win10

Windows 11: Win11

OS version

Edition Windows 11 Home Version 22H2 Installed on ‎22/‎10/‎13 OS build 22621.1555 Experience Windows Feature Experience Pack 1000.22640.1000.0

.NET version

7.0

WPF-UI NuGet version

2.0.3

Additional context

No response

yagudron avatar Apr 17 '23 09:04 yagudron

Take a look at the development branch, does the problem persist?

IvanDmitriev1 avatar Apr 17 '23 10:04 IvanDmitriev1

Yes, I have tried building from development - the same behavior.

image

yagudron avatar Apr 17 '23 11:04 yagudron

I have found the Windows setting which causes this.

Personalization > Colors image

It is reproduced only when it's on.

yagudron avatar Apr 17 '23 12:04 yagudron

Strangely, after enabling this option the title bar has not changed. But for example google chrome has changed. image

IvanDmitriev1 avatar Apr 17 '23 14:04 IvanDmitriev1

Interesting. I even asked my friend to try and he got the same results. Maybe there's more to it then.

yagudron avatar Apr 17 '23 14:04 yagudron

It only seems to occur when the window is focused. Anyone has a workaround yet?

olabacker avatar May 11 '23 09:05 olabacker

The Problem

This is caused by the user's Accent color being applied to the Window's titlebar.

Solutions

The quick workaround is to not have Show accent color on title bars and windows borders checked in the Windows Settings under Personalization > Colors.

If you don't want to change the setting via the Settings app, you can either do this directly in the Registry using regedit or via Powershell.

Using regedit:

Open regedit and navigate to HKCU:\Software\Microsoft\Windows\DWM for an item named ColorPrevalence. If you don't see this then right-click and create a new DWORD with that name. Set the value to 0 in order to disable it or 1 to enable it.

Using powershell:

# check current ColorPrevalence setting
Get-ItemPropertyValue -Path 'HKCU:\Software\Microsoft\Windows\DWM' -Name 'ColorPrevalence'

# disable ColorPrevalence (Accent colors on window titlebars and borders)
Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\DWM\' -Name 'ColorPrevalence' -Type DWord -Value 0

Other Methods

Aside from regedit and powershell you can create a .reg file, use the reg command in cmd, set via Group Policy, etc.

(Actually) Solving the Problem

Other than turning that Personalization setting off, there's likely a native Win32 API call that can be used to disable the title bar coloring with DWM. If I have some extra free time I'll see if I can put something together but for now here's a link to the documentation from Microsoft.

syntax-tm avatar Aug 25 '23 21:08 syntax-tm

图片

still have this problem

chenxuuu avatar Dec 19 '23 07:12 chenxuuu

bump

Jay-o-Way avatar Feb 06 '24 13:02 Jay-o-Way

Isn't it possible to set a window style that removes the titlebar, for a quick and dirty work-around?

Jay-o-Way avatar Feb 06 '24 13:02 Jay-o-Way

Workaround:

Put this into the MainWindow constructor:

    public MainWindow()
    {
        InitializeComponent();

        new WindowInteropHelper(this).EnsureHandle();

        SystemThemeWatcher.Watch(this, WindowBackdropType.Auto);
    }

The idea is that the window handle should be created before SystemThemeWatcher.Watch(...) runs.

This is because underneath there is a call to WindowBackdrop.RemoveBackdrop(...) and that fails if the window handle is not created.

In general I think that the whole idea of "lazy" window initialization is flawed.

drolevar avatar Feb 12 '24 15:02 drolevar

The actual issue is that ui:titlebar is taller then the area that get's colored by the accent color and the title is set to be at the center of the ui:titlebar

if you give the ui:titlebar a height of 30 this issue goes away

<ui:TitleBar Height="30" ... />

Before adding an height of 30 image

After adding an height of 30 image

The real issue with titlebar is that the icons on the system buttons stay black on dark mode until you hover the mouse on them

At start image

after hovering over the minimize button image

After hovering over all system buttons image

for this issue I haven't yet figured out a solution

537mfb avatar Mar 20 '24 17:03 537mfb

if you give the ui:titlebar a height of 30 this issue goes away

Should be 32, but #details :)

Jay-o-Way avatar Mar 20 '24 18:03 Jay-o-Way

Actually at least on my PC the height of the accent colored bar is 30px exactly

How did you get 32px @Jay-o-Way?

537mfb avatar Mar 21 '24 07:03 537mfb

How did you get 32px @Jay-o-Way?

Well, I mean, according to the design... https://learn.microsoft.com/windows/apps/design/basics/titlebar-design#standard-design

Jay-o-Way avatar Mar 21 '24 10:03 Jay-o-Way

Well, I mean, according to the design...

Interesting - an old wpf app without wpf-ui actually has 31px of accented colored titlebar while in my wpf-ui test app it's only 30px

Perhaps that 32px includes a border?

But you're right - after further testing although the accented area is only 30px high, only by making ui:titlebar 31px high does it cover the full accented area - and if i need an extra pixel that indicates theres actually a different colored border - so 32px is the correct height to use

537mfb avatar Mar 21 '24 10:03 537mfb

The fix for this issue is to use DwmSetWindowAttribute to set the DWMWA_CAPTION_COLOR attribute to 0xFFFFFFFE - this causes the title bar colour to not show when the mica effect is enabled with DWMWA_SYSTEMBACKDROP_TYPE (I'm assuming this is what wpfui uses to enable the mica effect.). However, this behaviour is undocumented here. I'm assuming this is what Notepad does as it has a mica effect in the title bar but doesn't have this issue.

aquinn39 avatar May 30 '24 12:05 aquinn39

Fixed? in #1122

pomianowski avatar Jun 10 '24 23:06 pomianowski