4
4
// All Rights Reserved.
5
5
6
6
using System . Diagnostics ;
7
+ using System . Windows . Data ;
7
8
using System . Windows . Input ;
8
9
using Wpf . Ui . Designer ;
9
10
using Wpf . Ui . Extensions ;
@@ -60,10 +61,20 @@ public class TitleBar : System.Windows.Controls.Control, IThemeControl
60
61
) ;
61
62
62
63
/// <summary>
63
- /// Property for <see cref="Header "/>.
64
+ /// Property for <see cref="HeaderLeft "/>.
64
65
/// </summary>
65
- public static readonly DependencyProperty HeaderProperty = DependencyProperty . Register (
66
- nameof ( Header ) ,
66
+ public static readonly DependencyProperty HeaderLeftProperty = DependencyProperty . Register (
67
+ nameof ( HeaderLeft ) ,
68
+ typeof ( object ) ,
69
+ typeof ( TitleBar ) ,
70
+ new PropertyMetadata ( null )
71
+ ) ;
72
+
73
+ /// <summary>
74
+ /// Property for <see cref="HeaderRight"/>.
75
+ /// </summary>
76
+ public static readonly DependencyProperty HeaderRightProperty = DependencyProperty . Register (
77
+ nameof ( HeaderRight ) ,
67
78
typeof ( object ) ,
68
79
typeof ( TitleBar ) ,
69
80
new PropertyMetadata ( null )
@@ -254,12 +265,21 @@ public string Title
254
265
}
255
266
256
267
/// <summary>
257
- /// Gets or sets the content displayed in the <see cref="TitleBar"/>.
268
+ /// Gets or sets the content displayed in the left side of the <see cref="TitleBar"/>.
269
+ /// </summary>
270
+ public object HeaderLeft
271
+ {
272
+ get => GetValue ( HeaderLeftProperty ) ;
273
+ set => SetValue ( HeaderLeftProperty , value ) ;
274
+ }
275
+
276
+ /// <summary>
277
+ /// Gets or sets the content displayed in right side of the <see cref="TitleBar"/>.
258
278
/// </summary>
259
- public object Header
279
+ public object HeaderRight
260
280
{
261
- get => GetValue ( HeaderProperty ) ;
262
- set => SetValue ( HeaderProperty , value ) ;
281
+ get => GetValue ( HeaderRightProperty ) ;
282
+ set => SetValue ( HeaderRightProperty , value ) ;
263
283
}
264
284
265
285
/// <summary>
@@ -420,6 +440,7 @@ public event TypedEventHandler<TitleBar, RoutedEventArgs> HelpClicked
420
440
private System . Windows . Controls . Grid _mainGrid = null ! ;
421
441
private System . Windows . Controls . ContentPresenter _icon = null ! ;
422
442
private readonly TitleBarButton [ ] _buttons = new TitleBarButton [ 4 ] ;
443
+ private readonly TextBlock _titleBlock ;
423
444
424
445
/// <summary>
425
446
/// Creates a new instance of the class and sets the default <see cref="FrameworkElement.Loaded"/> event.
@@ -430,6 +451,12 @@ public TitleBar()
430
451
431
452
dpiScale ??= VisualTreeHelper . GetDpi ( this ) ;
432
453
454
+ _titleBlock = new TextBlock ( ) ;
455
+ _titleBlock . VerticalAlignment = VerticalAlignment . Center ;
456
+ _titleBlock . SetBinding ( System . Windows . Controls . TextBlock . TextProperty , new Binding ( nameof ( Title ) ) { Source = this } ) ;
457
+ _titleBlock . SetBinding ( System . Windows . Controls . TextBlock . FontSizeProperty , new Binding ( nameof ( FontSize ) ) { Source = this } ) ;
458
+ HeaderLeft = _titleBlock ;
459
+
433
460
Loaded += OnLoaded ;
434
461
Unloaded += OnUnloaded ;
435
462
}
@@ -648,9 +675,19 @@ or User32.WM.NCLBUTTONUP
648
675
649
676
bool isMouseOverHeaderContent = false ;
650
677
651
- if ( message == User32 . WM . NCHITTEST && Header is UIElement headerUiElement )
678
+ if ( message == User32 . WM . NCHITTEST && ( HeaderRight is UIElement || HeaderLeft is UIElement ) )
652
679
{
653
- isMouseOverHeaderContent = headerUiElement . IsMouseOverElement ( lParam ) ;
680
+ UIElement ? headerLeftUIElement = HeaderLeft as UIElement ;
681
+ UIElement ? headerRightUiElement = HeaderRight as UIElement ;
682
+
683
+ if ( headerLeftUIElement is not null && headerLeftUIElement != _titleBlock )
684
+ {
685
+ isMouseOverHeaderContent = headerLeftUIElement . IsMouseOverElement ( lParam ) || ( headerRightUiElement ? . IsMouseOverElement ( lParam ) ?? false ) ;
686
+ }
687
+ else
688
+ {
689
+ isMouseOverHeaderContent = headerRightUiElement ? . IsMouseOverElement ( lParam ) ?? false ;
690
+ }
654
691
}
655
692
656
693
switch ( message )
0 commit comments