Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to change title bar color in MAUI UWP #19252

Open
Rohit123400000000000 opened this issue Dec 6, 2023 · 7 comments
Open

Not able to change title bar color in MAUI UWP #19252

Rohit123400000000000 opened this issue Dec 6, 2023 · 7 comments
Labels
area-controls-window Window platform/windows 🪟 potential-regression This issue described a possible regression on a currently supported version., verification pending s/needs-attention Issue has more information and needs another look t/bug Something isn't working t/desktop The issue relates to desktop scenarios (MacOS/MacCatalyst/Windows/WinUI/WinAppSDK)
Milestone

Comments

@Rohit123400000000000
Copy link

Description

We are not able to change title color of the MAUI UWP application , it is showing like darkgray color, we have to apply many approached but not able to fix that issue.

This is one of the sample code but we was apply many things like set property from the appshell etc. but color is not changed.

    var baseColor = Windows.UI.Color.FromArgb(255, 255, 255, 255);
    var nativeWindow = handler.PlatformView;
    nativeWindow.Activate();
    AppWindow appWindow = AppWindow.GetFromWindowId(Win32Interop.GetWindowIdFromWindow(WinRT.Interop.WindowNative.GetWindowHandle(nativeWindow)));
    appWindow.TitleBar.ButtonBackgroundColor = appWindow.TitleBar.BackgroundColor = Windows.UI.Color.FromArgb(255, 255, 255, 255);
    appWindow.TitleBar.ButtonPressedBackgroundColor = Windows.UI.Color.FromArgb(255, 255, 255, 255);
    appWindow.TitleBar.ForegroundColor = Windows.UI.Color.FromArgb(0, 0, 0, 0);
    appWindow.TitleBar.IconShowOptions = IconShowOptions.HideIconAndSystemMenu;
    appWindow.TitleBar.ButtonForegroundColor = Windows.UI.Color.FromArgb(255, 255, 255, 255);

it is still show gray color after the title bar in UWP

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

7.0.101

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

@Rohit123400000000000 Rohit123400000000000 added the t/bug Something isn't working label Dec 6, 2023
@jfversluis
Copy link
Member

I see you mention .NET 7, could you please try if anything changes when you use .NET 8?

You'll always want to (additionally) test the latest available version to see if we fixed already.

@jfversluis jfversluis added platform/windows 🪟 s/needs-info Issue needs more info from the author labels Dec 6, 2023
@ghost
Copy link

ghost commented Dec 6, 2023

Hi @Rohit123400000000000. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@samhouts samhouts added the potential-regression This issue described a possible regression on a currently supported version., verification pending label Dec 7, 2023
@olographio
Copy link

olographio commented Dec 8, 2023

Hi, I'm having the same issue after updating to .NET8. I'm using MAUI with WinUI however. I do something extremely similar, but to no avail. It's as if the title bar was frozen to the OS defaults. Everything was working flawlessly with .NET 7.

Screenshot:
image

My code:

private MauiWinUIApplication WinUIApp => MPC.MForms.WinUI.App.Current;
private msUIXaml.Window NativeWindow => (msUIXaml.Window)Application.Current.Windows.First().Handler.PlatformView;
private msUIWindowing.AppWindow m_appWindow = null;
private msUIWindowing.AppWindow AppWindow {
    get { 
        if(m_appWindow == null){
            var windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(this.NativeWindow);
            var windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(windowHandle);
            m_appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
            m_appWindow.Changed += AppWindow_OnChanged;
        }
        return m_appWindow;
    }
}

private msUIWindowing.AppWindowTitleBar m_titleBar = null;
private msUIWindowing.AppWindowTitleBar TitleBar => m_titleBar ?? (m_titleBar = this.AppWindow.TitleBar);

public override void ApplyTitleBarColor(Color toColor) {
    var winUiColor = toColor.ToWindowsColor();

    var windowCaptionBackgroundBrush = (msUIMedia.SolidColorBrush)this.WinUIApp.Resources["WindowCaptionBackground"];
    windowCaptionBackgroundBrush.Color = winUiColor;

    var windowCaptionBackgroundDisabledBrush = (msUIMedia.SolidColorBrush)this.WinUIApp.Resources["WindowCaptionBackgroundDisabled"];
    windowCaptionBackgroundDisabledBrush.Color = winUiColor;

    var closeButtonBackgroundPointerOverBrush = (msUIMedia.SolidColorBrush)this.WinUIApp.Resources["CloseButtonBackgroundPointerOver"];
    closeButtonBackgroundPointerOverBrush.Color = winUiColor;

    this.TitleBar.InactiveBackgroundColor = winUiColor;
    this.TitleBar.BackgroundColor = winUiColor;
    this.TitleBar.ForegroundColor = winUiColor;
    this.TitleBar.ButtonBackgroundColor = winUiColor;
    this.TitleBar.ButtonHoverBackgroundColor = winUiColor;
    this.TitleBar.ButtonInactiveBackgroundColor = winUiColor;
    this.TitleBar.ButtonPressedBackgroundColor = winUiColor;
}

TitleBar.ExtendsContentIntoTitleBar does nothing and using a custom title bar by adding code to WinUI's platform app.xaml works, but the background color cannot be changed. (Like you can add text, but the background color is locked to the OS defaults). It's weird.

Screenshot:

image

The code:

<maui:MauiWinUIApplication
    x:Class="MPC.MForms.WinUI.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:xaml="using:Microsoft.UI.Xaml"
    xmlns:maui="using:Microsoft.Maui"
    xmlns:local="using:MPC.MForms.WinUI">
    <maui:MauiWinUIApplication.Resources>

        <DataTemplate x:Key="MauiAppTitleBarTemplate">
            <Border
                Background="Green"
                Canvas.ZIndex="1" 
                VerticalAlignment="Stretch"
                Margin="0,0,0,0">
                <TextBlock 
                    VerticalAlignment="Center"
                    HorizontalAlignment="Center"
                    Text="Hello World" 
                    FontWeight="Bold"/>
            </Border>
        </DataTemplate>
...

Thank you to whoever looks into that ; )

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Dec 8, 2023
@PureWeen PureWeen removed the s/needs-attention Issue has more information and needs another look label Dec 13, 2023
@PureWeen PureWeen added this to the Backlog milestone Dec 13, 2023
@ghost
Copy link

ghost commented Dec 13, 2023

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

@Foda
Copy link
Member

Foda commented Dec 13, 2023

@Rohit123400000000000 we have a bigger story to add better titlebar/window customization in MAUI specifically for Windows, but an easy workaround is to just change the Border in your template to a Grid

@PureWeen PureWeen added the s/needs-info Issue needs more info from the author label Dec 13, 2023
@ghost
Copy link

ghost commented Dec 13, 2023

Hi @Rohit123400000000000. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@olographio
Copy link

olographio commented Dec 13, 2023

@Foda That's great news. I think customizing the title bar should be easy and readily available. It adds a lot of style to an app.

As for the workaround, thank you. I will try later. No offense, but when upgrading to .net8 I faced a lot of issues and I'm not ready to deal with that now. It's as if MAUI controls started to behave drastically differently.

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Dec 13, 2023
@samhouts samhouts added the legacy-area-desktop Windows / WinUI / Project Reunion & Mac Catalyst / macOS specifics (Menus & other Controls)) label Jan 4, 2024
@Eilon Eilon added t/desktop The issue relates to desktop scenarios (MacOS/MacCatalyst/Windows/WinUI/WinAppSDK) area-controls-window Window and removed legacy-area-desktop Windows / WinUI / Project Reunion & Mac Catalyst / macOS specifics (Menus & other Controls)) labels May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-window Window platform/windows 🪟 potential-regression This issue described a possible regression on a currently supported version., verification pending s/needs-attention Issue has more information and needs another look t/bug Something isn't working t/desktop The issue relates to desktop scenarios (MacOS/MacCatalyst/Windows/WinUI/WinAppSDK)
Projects
None yet
Development

No branches or pull requests

7 participants