diff --git a/src/Wpf.Ui/Controls/TitleBar/TitleBar.xaml b/src/Wpf.Ui/Controls/TitleBar/TitleBar.xaml index 110a281b8..f033043fd 100644 --- a/src/Wpf.Ui/Controls/TitleBar/TitleBar.xaml +++ b/src/Wpf.Ui/Controls/TitleBar/TitleBar.xaml @@ -41,7 +41,7 @@ Width="72" Height="72" Focusable="False"> - + diff --git a/src/Wpf.Ui/Controls/TitleBar/TitleBarButton.cs b/src/Wpf.Ui/Controls/TitleBar/TitleBarButton.cs index 33d2deb9e..04d93633e 100644 --- a/src/Wpf.Ui/Controls/TitleBar/TitleBarButton.cs +++ b/src/Wpf.Ui/Controls/TitleBar/TitleBarButton.cs @@ -43,6 +43,18 @@ public class TitleBarButton : Wpf.Ui.Controls.Button nameof(MouseOverButtonsForeground), typeof(Brush), typeof(TitleBarButton), + new FrameworkPropertyMetadata( + null, + FrameworkPropertyMetadataOptions.Inherits + ) + ); + /// + /// Property for . + /// + public static readonly DependencyProperty RenderButtonsForegroundProperty = DependencyProperty.Register( + nameof(RenderButtonsForeground), + typeof(Brush), + typeof(TitleBarButton), new FrameworkPropertyMetadata( SystemColors.ControlTextBrush, FrameworkPropertyMetadataOptions.Inherits @@ -66,23 +78,52 @@ public Brush ButtonsForeground get => (Brush)GetValue(ButtonsForegroundProperty); set => SetValue(ButtonsForegroundProperty, value); } + /// /// Foreground of the navigation buttons while mouse over. /// - public Brush MouseOverButtonsForeground + public Brush? MouseOverButtonsForeground { get => (Brush)GetValue(MouseOverButtonsForegroundProperty); set => SetValue(MouseOverButtonsForegroundProperty, value); } + public Brush RenderButtonsForeground + { + get => (Brush)GetValue(RenderButtonsForegroundProperty); + set => SetValue(RenderButtonsForegroundProperty, value); + } + public bool IsHovered { get; private set; } private User32.WM_NCHITTEST _returnValue; private Brush _defaultBackgroundBrush = Brushes.Transparent; //Should it be transparent? - private Brush _cacheButtonsForeground = SystemColors.ControlTextBrush; // cache ButtonsForeground while mouse over private bool _isClickedDown; + public TitleBarButton() + { + Loaded += TitleBarButton_Loaded; + Unloaded += TitleBarButton_Unloaded; + } + + private void TitleBarButton_Unloaded(object sender, RoutedEventArgs e) + { + DependencyPropertyDescriptor.FromProperty(ButtonsForegroundProperty, typeof(Brush)) + .RemoveValueChanged(this, OnButtonsForegroundChanged); + } + + private void TitleBarButton_Loaded(object sender, RoutedEventArgs e) + { + DependencyPropertyDescriptor.FromProperty(ButtonsForegroundProperty, typeof(Brush)) + .AddValueChanged(this, OnButtonsForegroundChanged); + } + + private void OnButtonsForegroundChanged(object sender, EventArgs e) + { + SetCurrentValue(RenderButtonsForegroundProperty, IsHovered ? MouseOverButtonsForeground : ButtonsForeground); + } + /// /// Forces button background to change. /// @@ -92,8 +133,11 @@ public void Hover() return; Background = MouseOverBackground; - _cacheButtonsForeground = ButtonsForeground; - ButtonsForeground = MouseOverButtonsForeground; + if (MouseOverButtonsForeground != null) + { + RenderButtonsForeground = MouseOverButtonsForeground; + } + IsHovered = true; } @@ -106,7 +150,7 @@ public void RemoveHover() return; Background = _defaultBackgroundBrush; - ButtonsForeground = _cacheButtonsForeground; + RenderButtonsForeground = ButtonsForeground; IsHovered = false; _isClickedDown = false;