Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
37 changes: 26 additions & 11 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 @@ -685,20 +704,15 @@ or PInvoke.WM_NCLBUTTONUP

if (message == PInvoke.WM_NCHITTEST)
{
if (TrailingContent is UIElement || Header is UIElement)
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;

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

htResult = GetWindowBorderHitTestResult(hwnd, lParam);
Expand All @@ -725,6 +739,7 @@ or PInvoke.WM_NCLBUTTONUP
case PInvoke.WM_NCHITTEST when this.IsMouseOverElement(lParam) && !isMouseOverHeaderContent:
handled = true;
return (IntPtr)PInvoke.HTCAPTION;

default:
return IntPtr.Zero;
}
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
Loading