Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Wpf.Ui/Controls/TitleBar/TitleBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
Width="72"
Height="72"
Focusable="False">
<Path x:Name="CanvasPath" Fill="{TemplateBinding ButtonsForeground}" />
<Path x:Name="CanvasPath" Fill="{TemplateBinding RenderButtonsForeground}" />
</Canvas>
</Viewbox>
</Grid>
Expand Down
54 changes: 49 additions & 5 deletions src/Wpf.Ui/Controls/TitleBar/TitleBarButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ public class TitleBarButton : Wpf.Ui.Controls.Button
nameof(MouseOverButtonsForeground),
typeof(Brush),
typeof(TitleBarButton),
new FrameworkPropertyMetadata(
null,
FrameworkPropertyMetadataOptions.Inherits
)
);
/// <summary>
/// Property for <see cref="RenderButtonsForeground"/>.
/// </summary>
public static readonly DependencyProperty RenderButtonsForegroundProperty = DependencyProperty.Register(
nameof(RenderButtonsForeground),
typeof(Brush),
typeof(TitleBarButton),
new FrameworkPropertyMetadata(
SystemColors.ControlTextBrush,
FrameworkPropertyMetadataOptions.Inherits
Expand All @@ -66,23 +78,52 @@ public Brush ButtonsForeground
get => (Brush)GetValue(ButtonsForegroundProperty);
set => SetValue(ButtonsForegroundProperty, value);
}

/// <summary>
/// Foreground of the navigation buttons while mouse over.
/// </summary>
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);
}

/// <summary>
/// Forces button background to change.
/// </summary>
Expand All @@ -92,8 +133,11 @@ public void Hover()
return;

Background = MouseOverBackground;
_cacheButtonsForeground = ButtonsForeground;
ButtonsForeground = MouseOverButtonsForeground;
if (MouseOverButtonsForeground != null)
{
RenderButtonsForeground = MouseOverButtonsForeground;
}

IsHovered = true;
}

Expand All @@ -106,7 +150,7 @@ public void RemoveHover()
return;

Background = _defaultBackgroundBrush;
ButtonsForeground = _cacheButtonsForeground;
RenderButtonsForeground = ButtonsForeground;

IsHovered = false;
_isClickedDown = false;
Expand Down