Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 33 additions & 28 deletions src/Wpf.Ui/Controls/TitleBar/TitleBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ public partial class TitleBar : System.Windows.Controls.Control, IThemeControl
new PropertyMetadata(null)
);

/// <summary>
/// Property for <see cref="CenterContent"/>.
/// </summary>
public static readonly DependencyProperty CenterContentProperty = DependencyProperty.Register(
nameof(CenterContent),
typeof(object),
typeof(TitleBar),
new PropertyMetadata(null)
);

/// <summary>
/// Property for <see cref="TrailingContent"/>.
/// </summary>
Expand Down Expand Up @@ -233,6 +243,15 @@ public object? Header
set => SetValue(HeaderProperty, value);
}

/// <summary>
/// Gets or sets the content displayed in the center of the <see cref="TitleBar"/>.
/// </summary>
public object? CenterContent
{
get => GetValue(CenterContentProperty);
set => SetValue(CenterContentProperty, value);
}

/// <summary>
/// Gets or sets the content displayed in right side of the <see cref="TitleBar"/>.
/// </summary>
Expand Down Expand Up @@ -683,37 +702,23 @@ or PInvoke.WM_NCLBUTTONUP
bool isMouseOverHeaderContent = false;
IntPtr htResult = (IntPtr)PInvoke.HTNOWHERE;

if (message == PInvoke.WM_NCHITTEST)
{
if (TrailingContent is UIElement || Header is UIElement)
{
UIElement? headerRightUiElement = TrailingContent as UIElement;

if (Header is UIElement headerLeftUIElement && headerLeftUIElement != _titleBlock)
{
isMouseOverHeaderContent =
headerLeftUIElement.IsMouseOverElement(lParam)
|| (headerRightUiElement?.IsMouseOverElement(lParam) ?? false);
}
else
{
isMouseOverHeaderContent = headerRightUiElement?.IsMouseOverElement(lParam) ?? false;
}
}

htResult = GetWindowBorderHitTestResult(hwnd, lParam);
}
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
Contributor 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
Contributor Author

Choose a reason for hiding this comment

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

fixed

{
case PInvoke.WM_NCHITTEST when CloseWindowByDoubleClickOnIcon && _icon.IsMouseOverElement(lParam):
// Ideally, clicking on the icon should open the system menu, but when the system menu is opened manually, double-clicking on the icon does not close the window
Expand Down
12 changes: 10 additions & 2 deletions src/Wpf.Ui/Controls/TitleBar/TitleBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<!-- Title text or other header content -->
Expand All @@ -145,15 +146,22 @@
HorizontalAlignment="Left"
Content="{TemplateBinding Header}" />

<!-- Additional header content -->
<!-- Centered content -->
<ContentPresenter
Grid.Column="1"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding CenterContent}" />

<!-- Additional header content -->
<ContentPresenter
Grid.Column="2"
HorizontalAlignment="Right"
Content="{TemplateBinding TrailingContent}" />

<!-- Navigation buttons - Close, Restore, Maximize, Minimize -->
<Grid
Grid.Column="2"
Grid.Column="3"
HorizontalAlignment="Right"
VerticalAlignment="Top">
<Grid.ColumnDefinitions>
Expand Down