Skip to content

Conversation

@luca-domenichini
Copy link

@luca-domenichini luca-domenichini commented Jul 11, 2025

This PR is fix for #1483
It adds a CenterContent DependencyProperty 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:

  • Update
  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes

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.

@github-actions github-actions bot added controls Changes to the appearance or logic of custom controls. styles Topic is related to styles PR Pull request dotnet release titlebar Titlebar updates labels Jul 11, 2025
@github-actions github-actions bot added the ⭐ top pull request Top pull request. label Jul 24, 2025
@pomianowski pomianowski linked an issue Nov 7, 2025 that may be closed by this pull request
@pomianowski pomianowski changed the title ADD TitleBar CenterContent property, fix for #1483 feat(controls): Add TitleBar CenterContent property Nov 7, 2025
Copilot AI review requested due to automatic review settings November 12, 2025 14:55
Copilot finished reviewing on behalf of luca-domenichini November 12, 2025 14:58
Copy link
Contributor

Copilot AI left a 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 CenterContent dependency 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

Comment on lines 705 to 719
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);
}
Copy link

Copilot AI Nov 12, 2025

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.

Copilot uses AI. Check for mistakes.
Copy link
Author

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)
Copy link

Copilot AI Nov 12, 2025

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.

Suggested change
switch (message)
switch (message)

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor

Copilot AI left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

controls Changes to the appearance or logic of custom controls. dotnet PR Pull request release ⭐ top pull request Top pull request. styles Topic is related to styles titlebar Titlebar updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TitleBar - ADD support for a centered content area

1 participant