diff --git a/src/Wpf.Ui.Gallery/Views/Windows/SandboxWindow.xaml b/src/Wpf.Ui.Gallery/Views/Windows/SandboxWindow.xaml index 5d5ee5799..847938aae 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 a2b4e9010..016361533 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.Extensions; @@ -60,10 +61,20 @@ public class TitleBar : System.Windows.Controls.Control, IThemeControl ); /// - /// Property for . + /// Property for . /// - public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register( - nameof(Header), + public static readonly DependencyProperty HeaderLeftProperty = DependencyProperty.Register( + nameof(HeaderLeft), + typeof(object), + typeof(TitleBar), + new PropertyMetadata(null) + ); + + /// + /// Property for . + /// + public static readonly DependencyProperty HeaderRightProperty = DependencyProperty.Register( + nameof(HeaderRight), typeof(object), typeof(TitleBar), new PropertyMetadata(null) @@ -254,12 +265,21 @@ 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 HeaderLeft + { + get => GetValue(HeaderLeftProperty); + set => SetValue(HeaderLeftProperty, value); + } + + /// + /// Gets or sets the content displayed in right side of the . /// - public object Header + public object HeaderRight { - get => GetValue(HeaderProperty); - set => SetValue(HeaderProperty, value); + get => GetValue(HeaderRightProperty); + set => SetValue(HeaderRightProperty, value); } /// @@ -420,6 +440,7 @@ public event TypedEventHandler HelpClicked private System.Windows.Controls.Grid _mainGrid = null!; private System.Windows.Controls.ContentPresenter _icon = null!; private readonly TitleBarButton[] _buttons = new TitleBarButton[4]; + private readonly TextBlock _titleBlock; /// /// Creates a new instance of the class and sets the default event. @@ -430,6 +451,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 }); + HeaderLeft = _titleBlock; + Loaded += OnLoaded; Unloaded += OnUnloaded; } @@ -648,9 +675,19 @@ or User32.WM.NCLBUTTONUP bool isMouseOverHeaderContent = false; - if (message == User32.WM.NCHITTEST && Header is UIElement headerUiElement) + if (message == User32.WM.NCHITTEST && (HeaderRight is UIElement || HeaderLeft is UIElement)) { - isMouseOverHeaderContent = headerUiElement.IsMouseOverElement(lParam); + UIElement? headerLeftUIElement = HeaderLeft as UIElement; + UIElement? headerRightUiElement = HeaderRight 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 f033043fd..a3294c9df 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" /> - - - + + - + + + + + Content="{TemplateBinding HeaderRight}" />