Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Close Button icon color in TitleBar while mouse over #993

Merged
merged 3 commits into from
Mar 13, 2024
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
13 changes: 2 additions & 11 deletions src/Wpf.Ui/Controls/TitleBar/TitleBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<Setter Property="Height" Value="30" />
<Setter Property="MouseOverBackground" Value="{Binding Path=ButtonsBackground, RelativeSource={RelativeSource AncestorType={x:Type controls:TitleBar}}}" />
<Setter Property="ButtonsForeground" Value="{Binding Path=ButtonsForeground, RelativeSource={RelativeSource AncestorType={x:Type controls:TitleBar}}}" />
<Setter Property="MouseOverButtonsForeground" Value="{Binding Path=MouseOverButtonsForeground, RelativeSource={RelativeSource AncestorType={x:Type controls:TitleBar}}}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="FocusVisualStyle" Value="{DynamicResource DefaultControlFocusVisualStyle}" />
<Setter Property="SnapsToDevicePixels" Value="True" />
Expand Down Expand Up @@ -45,9 +46,6 @@
</Viewbox>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="LayoutRoot" Property="Background" Value="{Binding Path=MouseOverBackground, RelativeSource={RelativeSource TemplatedParent}}" />
</Trigger>
<Trigger Property="ButtonType" Value="{x:Static controls:TitleBarButtonType.Help}">
<Setter Property="CommandParameter" Value="{x:Static controls:TitleBarButtonType.Help}" />
<Setter TargetName="ViewBox" Property="Width" Value="13" />
Expand All @@ -74,14 +72,6 @@
<Setter Property="CommandParameter" Value="{x:Static controls:TitleBarButtonType.Close}" />
<Setter TargetName="CanvasPath" Property="Data" Value="M36,41.1,6.15,71a3.44,3.44,0,0,1-2.53,1A3.55,3.55,0,0,1,0,68.38a3.44,3.44,0,0,1,1.05-2.53L30.9,36,1.05,6.15A3.49,3.49,0,0,1,0,3.59,3.51,3.51,0,0,1,.28,2.18,3.42,3.42,0,0,1,1.05,1,3.82,3.82,0,0,1,2.21.28,3.58,3.58,0,0,1,3.62,0,3.44,3.44,0,0,1,6.15,1.05L36,30.9,65.85,1.05a3.49,3.49,0,0,1,2.56-1A3.39,3.39,0,0,1,69.8.28,3.8,3.8,0,0,1,71,1.05a3.8,3.8,0,0,1,.77,1.15A3.39,3.39,0,0,1,72,3.59a3.49,3.49,0,0,1-1,2.56L41.1,36,71,65.85a3.44,3.44,0,0,1,1,2.53,3.58,3.58,0,0,1-.28,1.41A3.82,3.82,0,0,1,71,71a3.42,3.42,0,0,1-1.14.77,3.66,3.66,0,0,1-4-.77Z" />
</Trigger>

<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="ButtonType" Value="{x:Static controls:TitleBarButtonType.Close}" />
<Condition Property="IsMouseOver" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Foreground" Value="#FFFFFFFF" />
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
Expand Down Expand Up @@ -193,6 +183,7 @@
x:Name="PART_CloseButton"
Grid.Column="4"
ButtonType="Close"
MouseOverButtonsForeground="White"
MouseOverBackground="{DynamicResource PaletteRedBrush}" />
</Grid>
</Grid>
Expand Down
26 changes: 25 additions & 1 deletion src/Wpf.Ui/Controls/TitleBar/TitleBarButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ internal class TitleBarButton : Wpf.Ui.Controls.Button
)
);

/// <summary>
/// Property for <see cref="MouseOverButtonsForeground"/>.
/// </summary>
public static readonly DependencyProperty MouseOverButtonsForegroundProperty = DependencyProperty.Register(
nameof(MouseOverButtonsForeground),
typeof(Brush),
typeof(TitleBarButton),
new FrameworkPropertyMetadata(
SystemColors.ControlTextBrush,
FrameworkPropertyMetadataOptions.Inherits
)
);

/// <summary>
/// Sets or gets the
/// </summary>
Expand All @@ -53,11 +66,20 @@ public Brush ButtonsForeground
get => (Brush)GetValue(ButtonsForegroundProperty);
set => SetValue(ButtonsForegroundProperty, value);
}
/// <summary>
/// Foreground of the navigation buttons while mouse over.
/// </summary>
public Brush MouseOverButtonsForeground
{
get => (Brush)GetValue(MouseOverButtonsForegroundProperty);
set => SetValue(MouseOverButtonsForegroundProperty, 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;

Expand All @@ -70,6 +92,8 @@ public void Hover()
return;

Background = MouseOverBackground;
_cacheButtonsForeground = ButtonsForeground;
ButtonsForeground = MouseOverButtonsForeground;
IsHovered = true;
}

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

Background = _defaultBackgroundBrush;
ButtonsForeground = _cacheButtonsForeground;

IsHovered = false;
_isClickedDown = false;
Expand Down Expand Up @@ -119,7 +144,6 @@ internal bool ReactToHwndHook(User32.WM msg, IntPtr lParam, out IntPtr returnInt

RemoveHover();
return false;

case User32.WM.NCMOUSELEAVE: // Mouse leaves the window
RemoveHover();
return false;
Expand Down
Loading