question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The control buttons and shadow of a window with custom title bar is so weird

See original GitHub issue

Describe the bug

This is how a window with default system title bar looks like:

image

This is how a window with ExtendsContentIntoTitleBar=true looks like:

image

You can observe that the size (and the shape) of control buttons is not consistent:

image

Also, the depth of shadow of the window is not identical:

image

Steps to reproduce the bug

  1. Create a new blank WinUI 3 app with WASDK 1.1-preview3
  2. Set ExtendsContentIntoTitleBar to true

Expected behavior

The control buttons as well as shadow of the window should be identical both with system title bar and custom title bar.

NuGet package version

WinUI 3 - Windows App SDK 1.1 Preview 3: 1.1.0-preview3

Windows app type

  • UWP
  • Win32

Device form factor

Desktop

Windows version

Windows Insider Build (22621)

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:6
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rkarmancommented, Jun 29, 2022

Thanks for the ping here @riverar, I was not aware of this issue being logged.

@marb2000 / @MikeHillberg can one of you move this issue over to WinAppSDK so we can assign the proper owners and track this with the windowing team?

0reactions
RGarrido03commented, Mar 7, 2023

Ensure this is invoked after you .Activate() your window :

(stumbled over this in WinUI Git Hub example)

internal class Win32Ex
{
    private const int WAINACTIVE = 0x00;
    private const int WAACTIVE = 0x01;
    private const int WMACTIVATE = 0x0006;

    [DllImport("user32.dll")]
    private static extern IntPtr GetActiveWindow();

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    private static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, IntPtr lParam);

    public static void UpdateTitleBar(UIElement shell)
    {
        if (shell is FrameworkElement frameworkElement)
        {
            UpdateTitleBar(frameworkElement.RequestedTheme);
        }
        else
        {
            throw new ArgumentException($"Unable to update application title bar: {shell.GetType()}");
        }
    }

    public static void UpdateTitleBar(ElementTheme theme)
    {
        if (App.Window.ExtendsContentIntoTitleBar)
        {
            if (theme != ElementTheme.Default)
            {
                Application.Current.Resources["WindowCaptionForeground"] = theme switch
                {
                    ElementTheme.Dark => new SolidColorBrush(Colors.White),
                    ElementTheme.Light => new SolidColorBrush(Colors.Black),
                    _ => new SolidColorBrush(Colors.Transparent)
                };

                Application.Current.Resources["WindowCaptionForegroundDisabled"] = theme switch
                {
                    ElementTheme.Dark => new SolidColorBrush(Color.FromArgb(0x66, 0xFF, 0xFF, 0xFF)),
                    ElementTheme.Light => new SolidColorBrush(Color.FromArgb(0x66, 0x00, 0x00, 0x00)),
                    _ => new SolidColorBrush(Colors.Transparent)
                };

                Application.Current.Resources["WindowCaptionButtonBackgroundPointerOver"] = theme switch
                {
                    ElementTheme.Dark => new SolidColorBrush(Color.FromArgb(0x33, 0xFF, 0xFF, 0xFF)),
                    ElementTheme.Light => new SolidColorBrush(Color.FromArgb(0x33, 0x00, 0x00, 0x00)),
                    _ => new SolidColorBrush(Colors.Transparent)
                };

                Application.Current.Resources["WindowCaptionButtonBackgroundPressed"] = theme switch
                {
                    ElementTheme.Dark => new SolidColorBrush(Color.FromArgb(0x66, 0xFF, 0xFF, 0xFF)),
                    ElementTheme.Light => new SolidColorBrush(Color.FromArgb(0x66, 0x00, 0x00, 0x00)),
                    _ => new SolidColorBrush(Colors.Transparent)
                };

                Application.Current.Resources["WindowCaptionButtonStrokePointerOver"] = theme switch
                {
                    ElementTheme.Dark => new SolidColorBrush(Colors.White),
                    ElementTheme.Light => new SolidColorBrush(Colors.Black),
                    _ => new SolidColorBrush(Colors.Transparent)
                };

                Application.Current.Resources["WindowCaptionButtonStrokePressed"] = theme switch
                {
                    ElementTheme.Dark => new SolidColorBrush(Colors.White),
                    ElementTheme.Light => new SolidColorBrush(Colors.Black),
                    _ => new SolidColorBrush(Colors.Transparent)
                };
            }

            Application.Current.Resources["WindowCaptionBackground"] = new SolidColorBrush(Colors.Transparent);
            Application.Current.Resources["WindowCaptionBackgroundDisabled"] = new SolidColorBrush(Colors.Transparent);

            var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(App.Window);

            if (hwnd == GetActiveWindow())
            {
                SendMessage(hwnd, WMACTIVATE, WAINACTIVE, IntPtr.Zero);
                SendMessage(hwnd, WMACTIVATE, WAACTIVE, IntPtr.Zero);
            }
            else
            {
                SendMessage(hwnd, WMACTIVATE, WAACTIVE, IntPtr.Zero);
                SendMessage(hwnd, WMACTIVATE, WAINACTIVE, IntPtr.Zero);
            }
        }
    }
}

Thank you very much!! I’ll try that later today 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Have a shadow without title bars as a window decoration?
Click add, detect window properties and then click on the window/application you want, and then enable "hide window title bar".
Read more >
Windows 10 strange behavior of title bar
1 Answer 1 · Press Windows Key · Once you are in Registry Editor go to the key: HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics · Click on ......
Read more >
Tauri & ReactJS Part 12 - Custom Title Bar on Windows
In this video we'll create custom title bar for Windows while accounting for the scrollbar.
Read more >
Accent color is not used in title bars, start or task bar.
I've turned on "Manual" for "Accent Color" and selected "Dark Blue". Not a single window has a dark blue title bar, nor does....
Read more >
Custom Titlebar with frame in PyQt5 - python
I've tried modifying the window flags: With not window flags, the window is both re-sizable and movable. But no custom buttons. Using self....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found