-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Windows] Add TitleBar Control #23019
Conversation
…s on the Window such as leading + trailing content, color, etc.
Fix hide/show titlebar control not working
Add titlebar to sample page
…allows XAML defined titlebars w/ bindings
Fix PublicAPI defs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow this is super cool! Few questions from me!
Update sample
How do we plan to add support for this with Catalyst? If you want to use something like That uses specific NSToolBar items and a layout system where you set identifiers and set the flexibility of where items should appear. The TitleBar API allows for arbitrary existing controls and layout which AFAIK wouldn't work with that delegate. So if you want arbitrary controls, you would probably need to do something special with the UIWindow, merge the title bar into the inner content, and handle the managing the layout yourself. Or there could be other ways to create a more "native" looking titlebar on Catalyst that uses arbitrary controls. Making sure we have a plan for that now before deciding on this approach only to see it won't work on MacOS wouldn't be ideal. |
Yeah, we did talk briefly about this. One of the reasons why I made it a native MAUI control was so that we could just plop it into the "titlebar area" on both Win and Mac. I know it's possible to draw whatever custom control you want in the TitleBar (see: Edge w/ tabs) but I'm not sure what API does that, or what exactly the behavior is (maybe https://developer.apple.com/documentation/uikit/mac_catalyst/removing_the_title_bar_in_your_mac_app_built_with_mac_catalyst ??). I'm going to play around today to see how that API works |
Update sample
Personally I have a couple concerns about this one - mostly around it not considering catalyst yet.
There's absolutely no shame in that. We shouldn't need multiple ways of doing the same thing on the various XAML frameworks (* cough * TextBlock/Label * cough *), even if the WinUI API could have been cleaner. But again I still think it makes sense to diverge for the sake of crossplatform when necessary, but without Catalyst in the early designs in this PR, it might be hard to know whether the API should have differed to support them both more naturally. @drasticactions also some valid raised concerns along those lines. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I initially add the content I can't interact with it
But if I add/remove the trailing content then the content becomes interactable
Should we fix this issue?
#17723
base.OnAppearing(); | ||
Window.TitleBar = _customTitleBar; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be removed again when the page closes?
It does feel slightly weird to have the contentpage mess with the app-wide window. That might be more appropriate to use AppShell for instead, since that requires to be the root of the window content and hosts pages inside it.
Fix titlebar title spacing w/ default behavior Fix titlebar content added not allowing hit test Fix missing public API
The nice thing about this control is that because it's fully implemented in MAUI we also have full flexibility over how it appears in the app. I've gotten this to work in a playground app easily using a combo of adding the interface XAML code for macOS title bar<Grid
IgnoreSafeArea="True"
RowDefinitions="60, *">
<TitleBar
HorizontalOptions="Fill"
HeightRequest="64"
BackgroundColor="#512BD4">
<TitleBar.Content>
<HorizontalStackLayout
Spacing="4"
HorizontalOptions="Center"
VerticalOptions="Center"
IgnoreSafeArea="True">
<Button
BorderWidth="0"
Text=""
FontFamily="Ionicons"
FontSize="14"
TextColor="White"
VerticalOptions="Center"
WidthRequest="40"
Padding="0"/>
<Button
BorderWidth="0"
Text=""
FontFamily="Ionicons"
FontSize="14"
TextColor="White"
VerticalOptions="Center"
WidthRequest="40"
Padding="0"/>
<Entry
Placeholder="Search"
WidthRequest="400"
VerticalOptions="Center"
HeightRequest="40"/>
</HorizontalStackLayout>
</TitleBar.Content>
<TitleBar.TrailingContent>
<HorizontalStackLayout
Spacing="4"
Margin="0,0,16,0"
VerticalOptions="Center"
IgnoreSafeArea="True">
<Button
BorderWidth="0"
Text=""
FontFamily="Ionicons"
FontSize="16"
TextColor="White"
VerticalOptions="Center"
WidthRequest="50"
Padding="0"/>
<Button
WidthRequest="40"
HeightRequest="40"
BorderWidth="0"
CornerRadius="20"
BackgroundColor="Azure"
Text="MC"
FontSize="10"
TextColor="Black"
Padding="0"
VerticalOptions="Center">
</Button>
</HorizontalStackLayout>
</TitleBar.TrailingContent>
</TitleBar>
<Button
WidthRequest="200"
Text="Click Me"
Grid.Row="1"/>
</Grid> For now, I've added the |
This reverts commit d54c8fa.
* Custom titlebar control support spike * handle titlebar hit test elements automatically * sample * Added TitleBar property to Window: you can now set titlebar properties on the Window such as leading + trailing content, color, etc. * Add inactive colors for background + foreground Fix hide/show titlebar control not working * Fix issue w/ titlebar unhook on window close Add titlebar to sample page * Added `Window.SetTitleBar` function to set the window titlebar. This allows XAML defined titlebars w/ bindings * Revert some changes * Revert changes Fix PublicAPI defs * Error checkAdditional error checks for page nav * Update ITitlebar interface * Titlebar control is now a TemplatedView * Remove `SetTitlebar` API Update sample * Remove child * Use pattern matching * Add some docs * Fix missing publicapi bits * More public api bits * Missed some * Fix use of content presenter * Adjust passthrough logic * Fix titlebar height adjust for caption buttons * Fix override of default template not working * Cleanup * Fix default control template not being applied Add default style for TitleBar * Fix missing API for tizen * Fix sample issue Update sample * Fix missing title + icon when titlebar is not fully set Fix titlebar title spacing w/ default behavior Fix titlebar content added not allowing hit test Fix missing public API * Add IgnoreSafeArea for macOS * Tizen * Fix titlebar being set on window creation w/ template selector * Comment out templates --------- Co-authored-by: Mike Corsaro <[email protected]> Co-authored-by: Javier Suárez <[email protected]> # Conflicts: # src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt # src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt # src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt # src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt # src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt # src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt # src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt # src/Core/src/PublicAPI/net-tizen/PublicAPI.Unshipped.txt
* [Windows] Add TitleBar Control (#23019) * Custom titlebar control support spike * handle titlebar hit test elements automatically * sample * Added TitleBar property to Window: you can now set titlebar properties on the Window such as leading + trailing content, color, etc. * Add inactive colors for background + foreground Fix hide/show titlebar control not working * Fix issue w/ titlebar unhook on window close Add titlebar to sample page * Added `Window.SetTitleBar` function to set the window titlebar. This allows XAML defined titlebars w/ bindings * Revert some changes * Revert changes Fix PublicAPI defs * Error checkAdditional error checks for page nav * Update ITitlebar interface * Titlebar control is now a TemplatedView * Remove `SetTitlebar` API Update sample * Remove child * Use pattern matching * Add some docs * Fix missing publicapi bits * More public api bits * Missed some * Fix use of content presenter * Adjust passthrough logic * Fix titlebar height adjust for caption buttons * Fix override of default template not working * Cleanup * Fix default control template not being applied Add default style for TitleBar * Fix missing API for tizen * Fix sample issue Update sample * Fix missing title + icon when titlebar is not fully set Fix titlebar title spacing w/ default behavior Fix titlebar content added not allowing hit test Fix missing public API * Add IgnoreSafeArea for macOS * Tizen * Fix titlebar being set on window creation w/ template selector * Comment out templates --------- Co-authored-by: Mike Corsaro <[email protected]> Co-authored-by: Javier Suárez <[email protected]> # Conflicts: # src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt # src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt # src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt # src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt # src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt # src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt # src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt # src/Core/src/PublicAPI/net-tizen/PublicAPI.Unshipped.txt * Use new things --------- Co-authored-by: Mike Corsaro <[email protected]>
This PR is a draft and seeking API feedback for an initial release
Description of Change
This PR adds a new
TitleBar
control and API to set the TitleBar on aWindow
. It currently only applies to the Windows platform, but it's built entirely as a MAUI control to allow macOS support later.Please read the full API description here: #13023
Feature demo (PlatformSpecifics page in Maui.Controls.Sample):
titlebar.mp4
API/Usage
The primary API is the
Window.SetTitleBar
function -- which removes theTitleBar
control from the visual tree and inserts it as the native TitleBar (this approach was shamelessly copied from the WinAppSDK). This was used vs an attached property (ex:<Window.TitleBar>
) because it was difficult to get a validWindow
object when the property was first set.Example using XAML:
MainWindow.xaml
Example using code
MainPage.xaml.cs
Issues Fixed
Fixes #13023