Skip to content

Commit 9e1042a

Browse files
committed
Use Header instead of HeaderLeft and TrailingContent instead of HeaderRight
Refactor TitleBar properties for clarity and usability Renamed properties in the `TitleBar` class from `HeaderLeft` and `HeaderRight` to `Header` and `TrailingContent`. Updated XAML and C# files to reflect these changes, streamlining the structure of the `TitleBar`. Modified the constructor to set the `_titleBlock` to the new `Header` property. Adjusted hit testing logic in `WM.NCHITTEST` to accommodate the new property names, ensuring proper mouse interaction handling. These changes improve the overall clarity and usability of the `TitleBar` component.
1 parent dc3fcfa commit 9e1042a

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

src/Wpf.Ui.Gallery/Views/Windows/SandboxWindow.xaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<ui:TitleBar.Icon>
3131
<ui:ImageIcon Source="pack://application:,,,/Assets/wpfui.png" />
3232
</ui:TitleBar.Icon>
33-
<ui:TitleBar.HeaderLeft>
33+
<ui:TitleBar.Header>
3434
<Menu>
3535
<MenuItem Header="File">
3636
<MenuItem
@@ -72,8 +72,8 @@
7272
Header="Select All" />
7373
</ui:MenuItem>
7474
</Menu>
75-
</ui:TitleBar.HeaderLeft>
76-
<ui:TitleBar.HeaderRight>
75+
</ui:TitleBar.Header>
76+
<ui:TitleBar.TrailingContent>
7777
<Menu>
7878
<ui:MenuItem
7979
Foreground="{DynamicResource PaletteDeepOrangeBrush}"
@@ -88,7 +88,7 @@
8888
Foreground="{DynamicResource PaletteLightBlueBrush}"
8989
Icon="{ui:SymbolIcon ArrowClockwise24}" />
9090
</Menu>
91-
</ui:TitleBar.HeaderRight>
91+
</ui:TitleBar.TrailingContent>
9292
</ui:TitleBar>
9393

9494
<StackPanel Margin="24">

src/Wpf.Ui/Controls/TitleBar/TitleBar.cs

+16-17
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,20 @@ public class TitleBar : System.Windows.Controls.Control, IThemeControl
5454
);
5555

5656
/// <summary>
57-
/// Property for <see cref="HeaderLeft"/>.
57+
/// Property for <see cref="Header"/>.
5858
/// </summary>
59-
public static readonly DependencyProperty HeaderLeftProperty = DependencyProperty.Register(
60-
nameof(HeaderLeft),
59+
public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register(
60+
nameof(Header),
6161
typeof(object),
6262
typeof(TitleBar),
6363
new PropertyMetadata(null)
6464
);
6565

6666
/// <summary>
67-
/// Property for <see cref="HeaderRight"/>.
67+
/// Property for <see cref="TrailingContent"/>.
6868
/// </summary>
69-
public static readonly DependencyProperty HeaderRightProperty = DependencyProperty.Register(
70-
nameof(HeaderRight),
69+
public static readonly DependencyProperty TrailingContentProperty = DependencyProperty.Register(
70+
nameof(TrailingContent),
7171
typeof(object),
7272
typeof(TitleBar),
7373
new PropertyMetadata(null)
@@ -224,19 +224,19 @@ public string? Title
224224
/// <summary>
225225
/// Gets or sets the content displayed in the left side of the <see cref="TitleBar"/>.
226226
/// </summary>
227-
public object HeaderLeft
227+
public object Header
228228
{
229-
get => GetValue(HeaderLeftProperty);
230-
set => SetValue(HeaderLeftProperty, value);
229+
get => GetValue(HeaderProperty);
230+
set => SetValue(HeaderProperty, value);
231231
}
232232

233233
/// <summary>
234234
/// Gets or sets the content displayed in right side of the <see cref="TitleBar"/>.
235235
/// </summary>
236-
public object HeaderRight
236+
public object TrailingContent
237237
{
238-
get => GetValue(HeaderRightProperty);
239-
set => SetValue(HeaderRightProperty, value);
238+
get => GetValue(TrailingContentProperty);
239+
set => SetValue(TrailingContentProperty, value);
240240
}
241241

242242
/// <summary>
@@ -398,7 +398,6 @@ public event TypedEventHandler<TitleBar, RoutedEventArgs> HelpClicked
398398

399399
/*private System.Windows.Controls.Grid _mainGrid = null!;*/
400400
private System.Windows.Controls.ContentPresenter _icon = null!;
401-
private readonly TitleBarButton[] _buttons = new TitleBarButton[4];
402401
private readonly TextBlock _titleBlock;
403402

404403
/// <summary>
@@ -414,7 +413,7 @@ public TitleBar()
414413
_titleBlock.VerticalAlignment = VerticalAlignment.Center;
415414
_titleBlock.SetBinding(System.Windows.Controls.TextBlock.TextProperty, new Binding(nameof(Title)) { Source = this });
416415
_titleBlock.SetBinding(System.Windows.Controls.TextBlock.FontSizeProperty, new Binding(nameof(FontSize)) { Source = this });
417-
HeaderLeft = _titleBlock;
416+
Header = _titleBlock;
418417

419418
Loaded += OnLoaded;
420419
Unloaded += OnUnloaded;
@@ -647,10 +646,10 @@ or User32.WM.NCLBUTTONUP
647646

648647
bool isMouseOverHeaderContent = false;
649648

650-
if (message == User32.WM.NCHITTEST && (HeaderRight is UIElement || HeaderLeft is UIElement))
649+
if (message == User32.WM.NCHITTEST && (TrailingContent is UIElement || Header is UIElement))
651650
{
652-
UIElement? headerLeftUIElement = HeaderLeft as UIElement;
653-
UIElement? headerRightUiElement = HeaderRight as UIElement;
651+
UIElement? headerLeftUIElement = Header as UIElement;
652+
UIElement? headerRightUiElement = TrailingContent as UIElement;
654653

655654
if (headerLeftUIElement is not null && headerLeftUIElement != _titleBlock)
656655
{

src/Wpf.Ui/Controls/TitleBar/TitleBar.xaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@
142142
<ContentPresenter
143143
Grid.Column="0"
144144
HorizontalAlignment="Left"
145-
Content="{TemplateBinding HeaderLeft}" />
145+
Content="{TemplateBinding Header}" />
146146

147147
<!-- Additional header content -->
148148
<ContentPresenter
149149
Grid.Column="1"
150150
HorizontalAlignment="Right"
151-
Content="{TemplateBinding HeaderRight}" />
151+
Content="{TemplateBinding TrailingContent}" />
152152

153153
<!-- Navigation buttons - Close, Restore, Maximize, Minimize -->
154154
<Grid

0 commit comments

Comments
 (0)