diff --git a/src/Wpf.Ui.Gallery/Views/Windows/SandboxWindow.xaml b/src/Wpf.Ui.Gallery/Views/Windows/SandboxWindow.xaml index 5d5ee5799..facb3c035 100644 --- a/src/Wpf.Ui.Gallery/Views/Windows/SandboxWindow.xaml +++ b/src/Wpf.Ui.Gallery/Views/Windows/SandboxWindow.xaml @@ -30,6 +30,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Wpf.Ui/Controls/TitleBar/TitleBar.cs b/src/Wpf.Ui/Controls/TitleBar/TitleBar.cs index 487253a09..36812834c 100644 --- a/src/Wpf.Ui/Controls/TitleBar/TitleBar.cs +++ b/src/Wpf.Ui/Controls/TitleBar/TitleBar.cs @@ -4,6 +4,7 @@ // All Rights Reserved. using System.Diagnostics; +using System.Windows.Data; using System.Windows.Input; using Wpf.Ui.Designer; using Wpf.Ui.Input; @@ -52,13 +53,25 @@ public class TitleBar : System.Windows.Controls.Control, IThemeControl new PropertyMetadata(null) ); - /// Identifies the dependency property. + /// + /// Property for . + /// public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register( nameof(Header), typeof(object), typeof(TitleBar), new PropertyMetadata(null) ); + + /// + /// Property for . + /// + public static readonly DependencyProperty TrailingContentProperty = DependencyProperty.Register( + nameof(TrailingContent), + typeof(object), + typeof(TitleBar), + new PropertyMetadata(null) + ); /// Identifies the dependency property. public static readonly DependencyProperty ButtonsForegroundProperty = DependencyProperty.Register( @@ -209,13 +222,22 @@ public string? Title } /// - /// Gets or sets the content displayed in the . + /// Gets or sets the content displayed in the left side of the . /// - public object? Header + public object Header { get => GetValue(HeaderProperty); set => SetValue(HeaderProperty, value); } + + /// + /// Gets or sets the content displayed in right side of the . + /// + public object TrailingContent + { + get => GetValue(TrailingContentProperty); + set => SetValue(TrailingContentProperty, value); + } /// /// Gets or sets the foreground of the navigation buttons. @@ -376,6 +398,7 @@ public event TypedEventHandler HelpClicked /*private System.Windows.Controls.Grid _mainGrid = null!;*/ private System.Windows.Controls.ContentPresenter _icon = null!; + private readonly TextBlock _titleBlock; /// /// Initializes a new instance of the class and sets the default event. @@ -386,6 +409,12 @@ public TitleBar() dpiScale ??= VisualTreeHelper.GetDpi(this); + _titleBlock = new TextBlock(); + _titleBlock.VerticalAlignment = VerticalAlignment.Center; + _titleBlock.SetBinding(System.Windows.Controls.TextBlock.TextProperty, new Binding(nameof(Title)) { Source = this }); + _titleBlock.SetBinding(System.Windows.Controls.TextBlock.FontSizeProperty, new Binding(nameof(FontSize)) { Source = this }); + Header = _titleBlock; + Loaded += OnLoaded; Unloaded += OnUnloaded; } @@ -617,9 +646,19 @@ or User32.WM.NCLBUTTONUP bool isMouseOverHeaderContent = false; - if (message == User32.WM.NCHITTEST && Header is UIElement headerUiElement) + if (message == User32.WM.NCHITTEST && (TrailingContent is UIElement || Header is UIElement)) { - isMouseOverHeaderContent = headerUiElement.IsMouseOverElement(lParam); + UIElement? headerLeftUIElement = Header as UIElement; + UIElement? headerRightUiElement = TrailingContent as UIElement; + + if (headerLeftUIElement is not null && headerLeftUIElement != _titleBlock) + { + isMouseOverHeaderContent = headerLeftUIElement.IsMouseOverElement(lParam) || (headerRightUiElement?.IsMouseOverElement(lParam) ?? false); + } + else + { + isMouseOverHeaderContent = headerRightUiElement?.IsMouseOverElement(lParam) ?? false; + } } switch (message) diff --git a/src/Wpf.Ui/Controls/TitleBar/TitleBar.xaml b/src/Wpf.Ui/Controls/TitleBar/TitleBar.xaml index 82097c1e9..9dddd9b1c 100644 --- a/src/Wpf.Ui/Controls/TitleBar/TitleBar.xaml +++ b/src/Wpf.Ui/Controls/TitleBar/TitleBar.xaml @@ -118,7 +118,6 @@ VerticalAlignment="Center"> - @@ -126,34 +125,34 @@ x:Name="PART_Icon" Grid.Column="0" Height="16" - Margin="0,0,12,0" VerticalAlignment="Center" Content="{TemplateBinding Icon}" Focusable="False" RenderOptions.BitmapScalingMode="HighQuality" /> - - - + + - + + + +