-
-
Notifications
You must be signed in to change notification settings - Fork 915
feat(controls): Add TitleBar CenterContent property
#1484
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
base: main
Are you sure you want to change the base?
Conversation
minimizing changes
TitleBar CenterContent property
Merge 2025-11-12 from base repo
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.
Pull Request Overview
This PR adds a CenterContent property to the TitleBar control, enabling developers to place content in the center area of the title bar.
Key changes:
- New
CenterContentdependency property with getter/setter - Updated XAML template with additional grid column for centered content
- Enhanced mouse hit-testing logic to handle center content interactions
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Wpf.Ui/Controls/TitleBar/TitleBar.cs | Added CenterContent dependency property and updated window procedure hook to handle mouse-over detection for center content |
| src/Wpf.Ui/Controls/TitleBar/TitleBar.xaml | Added new grid column and ContentPresenter for center content, reordered existing columns |
| if (message == PInvoke.WM_NCHITTEST) | ||
| { | ||
| if (TrailingContent is UIElement || Header is UIElement || CenterContent is UIElement) | ||
| { | ||
| UIElement? headerLeftUIElement = Header as UIElement; | ||
| UIElement? headerCenterUIElement = CenterContent as UIElement; | ||
| UIElement? headerRightUiElement = TrailingContent as UIElement; | ||
|
|
||
| var e = new HwndProcEventArgs(hwnd, msg, wParam, lParam, isMouseOverHeaderContent); | ||
| WndProcInvoked?.Invoke(this, e); | ||
| isMouseOverHeaderContent = (headerLeftUIElement is not null && headerLeftUIElement != _titleBlock && headerLeftUIElement.IsMouseOverElement(lParam)) | ||
| || (headerCenterUIElement?.IsMouseOverElement(lParam) ?? false) | ||
| || (headerRightUiElement?.IsMouseOverElement(lParam) ?? false); | ||
| } | ||
|
|
||
| if (e.ReturnValue != null) | ||
| { | ||
| handled = e.Handled; | ||
| return e.ReturnValue ?? IntPtr.Zero; | ||
| } | ||
| htResult = GetWindowBorderHitTestResult(hwnd, lParam); | ||
| } |
Copilot
AI
Nov 12, 2025
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.
Tabs are used for indentation instead of spaces. According to the project's .editorconfig, C# files should use spaces (indent_style = space). Please replace tabs with spaces for consistent formatting.
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.
fixed
| } | ||
|
|
||
| switch (message) | ||
| switch (message) |
Copilot
AI
Nov 12, 2025
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.
Tab used for indentation instead of spaces. According to the project's .editorconfig, C# files should use spaces (indent_style = space). Please replace the tab with spaces.
| switch (message) | |
| switch (message) |
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.
fixed
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.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
|
Hi @pomianowski , is there something more I can do to make this PR go ahead? |
|
I had also used the same approach to allow user content in the center of the title bar, but I realized it might be a temporary workaround and didn't submit a PR. Later, I found that changing the The column where Changing it to Moreover, this method requires minimal changes, especially since no modifications are needed in the Back then, I wasn't very familiar with the PR process. I once accidentally included this change in a PR, but it was rejected — haha! |
|
I think your arguments are valuable. Thanks for adding your point of view ⭐ Let's hope for a review by the maintainers! ⭐ |
|
@apachezy thumb up the PR if you want to push it further 👍 |
|
So I suggest adopting the "TrailingContent.HorizontalAlignment = Stretch" approach, mark the TrailingContent property as obsolete, introduce a new property (e.g., "RemainingSpaceContent") to replace it, and then internally link TrailingContent to this new property. This way, the changes required are minimal. It avoids cluttering TitleBar with too many "Content" properties, while still meeting the requirements. Why not go for it? |
|
I'll wait for your new solution to be implemented, and I'll give you a ton of likes for it! 👍 |
|
hmm.. I think having just a new center property will not break existing applications. Changing the existing one as you suggest, also could break them. |
|
Hmm... I think this is just part of the natural process of software iteration. Changing the |
|
I see your point, for a brand new library would make more sense, and yes, for me would not be a problem since I'm making the PR and I would naturally adapt my code as well. Though, I think the kind of change you are suggesting should be approved by maintainers more carefully, and since I want this PR to go fast without breaking anyone.. well.. let's wait for @pomianowski to react to your points. Repeating myself: for me would be OK with your proposal. Just curious about owner directions. |
|
I feel that there are still some unresolved concerns in the current TitleBar implementation, particularly regarding the combination of WPF techniques and the Windows message–based approach. While it seems to be working correctly right now, this is largely thanks to the accumulated efforts of multiple contributors. I expect that more focused refinements will be needed in the future, so at this stage, I think it makes sense to achieve the required functionality with minimal changes. |
This PR is fix for #1483
It adds a
CenterContentDependencyProperty and a new column in the Grid of TitleBar, making developer able to put content in the center area of the titlebar.Moreover, with
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"we make developer able to align the centered area more precisely, to the left, center or right edge.Pull request type
Please check the type of change your PR introduces:
What is the current behavior?
Currently there are few, less obvious alternatives.
Issue Number: #1483
What is the new behavior?
Devs are now able to put content directly in the centered area of the title bar.