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

SetTitleBar not working on Windows #22178

Closed
bdovaz opened this issue May 2, 2024 · 7 comments
Closed

SetTitleBar not working on Windows #22178

bdovaz opened this issue May 2, 2024 · 7 comments
Labels
area-controls-window Window platform/windows 🪟 s/needs-info Issue needs more info from the author t/bug Something isn't working t/desktop The issue relates to desktop scenarios (MacOS/MacCatalyst/Windows/WinUI/WinAppSDK)

Comments

@bdovaz
Copy link

bdovaz commented May 2, 2024

Description

I am trying to customize the titlebar in Windows by following these steps:

https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.window.settitlebar

But no matter what you do, the SetTitleBar call does nothing.

Steps to Reproduce

builder.ConfigureLifecycleEvents(events =>
{
    events.AddWindows(windowsLifecycleBuilder =>
    {
        windowsLifecycleBuilder.OnWindowCreated(window =>
        {
            window.ExtendsContentIntoTitleBar = true;
            window.SetTitleBar(new MyWindow().AppTitleBar);
        });
    });
});

Link to public reproduction project repository

No response

Version with bug

8.0.21 SR4.1

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

No response

Did you find any workaround?

No

Relevant log output

No response

@bdovaz bdovaz added the t/bug Something isn't working label May 2, 2024
Copy link
Contributor

github-actions bot commented May 2, 2024

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@PureWeen
Copy link
Member

PureWeen commented May 3, 2024

Here's some info on how to customize the titlebar

#20976 (comment)

@PureWeen PureWeen added platform/windows 🪟 s/needs-info Issue needs more info from the author labels May 3, 2024
@bdovaz
Copy link
Author

bdovaz commented May 3, 2024

Here's some info on how to customize the titlebar

#20976 (comment)

@PureWeen I tried that but the following happens to me:

<DataTemplate x:Key="MauiAppTitleBarTemplate">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <TextBlock VerticalAlignment="Center" Text="MyText" />
        <TextBlock VerticalAlignment="Center" Grid.Column="2" Text="MyText2" />
    </Grid>
</DataTemplate>

Output (as you can see, on the right side it overlaps with the buttons of the window):

(AppShell.xaml -> Shell.FlyoutBehavior="Disabled")

image

(AppShell.xaml -> Shell.FlyoutBehavior="Flyout")

image

As you can see, even using this method I can't get it to work.

Besides, what you have not answered me is why SetTitleBar doesn't work, is it a MAUI bug? Am I doing something wrong? Because my idea was to follow the "Full customization" tutorial since I want the title bar to be interactive:

https://learn.microsoft.com/en-us/windows/apps/develop/title-bar#full-customization

@dotnet-policy-service dotnet-policy-service bot 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 May 3, 2024
@Eilon Eilon added the legacy-area-desktop Windows / WinUI / Project Reunion & Mac Catalyst / macOS specifics (Menus & other Controls)) label May 3, 2024
@drasticactions
Copy link
Contributor

I agree that what @PureWeen sent doesn't address your issue directly, but I don't think that "SetTitleBar" doesn't work, it's that you're not using it right, but you also couldn't because the way MAUI apps work. I'll try to explain my thought process.

  • First, your example code is wrong. If you're building a WinUI app, you would need to pass in a UIElement contained within the existing Window. You're passing in a new element (I don't know the type, since you didn't provide a sample) so it's not connected to anything, so it won't work no matter what.
  • So you would, generally, build a WinUI Window, create a UIElement within that Window to represent the TitleBar, then call SetTitleBar with that element. While you can create a new MAUI Window (which itself is a WinUI 3 Window, wrapped), you can't directly set elements contained within it, at least not easily.
  • What @PureWeen's example does show is that the TitleBar is already abstracted within MAUI and you can add additional elements within that. however to the best of my knowledge, elements contained within this TitleBar can't be interactive, apart from the hamburger menu on the left nav, because you would need further customization to allow buttons, etc, to be clickable.

So TL;DR

  • SetTitleBar does work if you pass in a UIElement...
  • But passing in a valid UIElement isn't trivial unless you hack underlying implementations of frameworks...
  • But there is a TitleBar you can customize through the Platform XAML...
  • But you probably can't add the elements you want to make it interactive without also hacking more of the window...

IMO, you would be better off using MAUI Native Embedding and creating a WinUI 3 app that contains MAUI Elements instead. That would give you full control of the WinUI 3 window without needing to deal with all of that overhead. I have an example of this here that could help you do it.

@PureWeen
Copy link
Member

PureWeen commented May 7, 2024

You can set interactive regions here

Rect[] IWindow.TitleBarDragRectangles
{
get
{
return (this.Handler as IWindowHandler)?.PlatformView?
.GetDefaultTitleBarDragRectangles(this.GetCurrentlyPresentedMauiContext());
}
}

@PureWeen PureWeen added s/needs-info Issue needs more info from the author and removed s/needs-attention Issue has more information and needs another look labels May 7, 2024
Copy link
Contributor

Hi @bdovaz. 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.

@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
@dotnet-policy-service dotnet-policy-service bot added the s/no-recent-activity Issue has had no recent activity label May 20, 2024
Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 24, 2024
@dotnet-policy-service dotnet-policy-service bot removed the s/no-recent-activity Issue has had no recent activity label Jun 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-window Window platform/windows 🪟 s/needs-info Issue needs more info from the author 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

4 participants