Skip to content

Commit

Permalink
Fix issue where scroll bar thumb color didn’t always change with theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinnara committed Dec 12, 2019
1 parent 5e604fb commit 289113b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
25 changes: 25 additions & 0 deletions ModernWpf/Controls/Primitives/ScrollBarThumbHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Windows;
using System.Windows.Controls.Primitives;

namespace ModernWpf.Controls.Primitives
{
public static class ScrollBarThumbHelper
{
public static readonly DependencyProperty IsExpandedProperty =
DependencyProperty.RegisterAttached(
"IsExpanded",
typeof(bool),
typeof(ScrollBarThumbHelper),
new PropertyMetadata(false));

public static bool GetIsExpanded(Thumb thumb)
{
return (bool)thumb.GetValue(IsExpandedProperty);
}

public static void SetIsExpanded(Thumb thumb, bool value)
{
thumb.SetValue(IsExpandedProperty, value);
}
}
}
12 changes: 12 additions & 0 deletions ModernWpf/Styles/ScrollBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@
RadiusY="{TemplateBinding primitives:ControlHelper.CornerRadius, Converter={StaticResource BottomRightCornerRadiusDoubleValueConverter}}"
SnapsToDevicePixels="True" />
<ControlTemplate.Triggers>
<Trigger Property="primitives:ScrollBarThumbHelper.IsExpanded" Value="True">
<Setter TargetName="ThumbVisual" Property="Fill" Value="{DynamicResource ScrollBarThumbBackground}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="ThumbVisual" Property="Fill" Value="{DynamicResource ScrollBarThumbFillPointerOver}" />
</Trigger>
Expand All @@ -170,6 +173,9 @@
RadiusY="{TemplateBinding primitives:ControlHelper.CornerRadius, Converter={StaticResource BottomRightCornerRadiusDoubleValueConverter8x}}"
SnapsToDevicePixels="True" />
<ControlTemplate.Triggers>
<Trigger Property="primitives:ScrollBarThumbHelper.IsExpanded" Value="True">
<Setter TargetName="ThumbVisual" Property="Fill" Value="{DynamicResource ScrollBarThumbBackground}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="ThumbVisual" Property="Fill" Value="{DynamicResource ScrollBarThumbFillPointerOver}" />
</Trigger>
Expand Down Expand Up @@ -319,6 +325,9 @@
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="VerticalThumb" Storyboard.TargetProperty="(primitives:ScrollBarThumbHelper.IsExpanded)">
<DiscreteBooleanKeyFrame KeyTime="0:0:0.5" Value="True" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</Border.Resources>
<VisualStateManager.VisualStateGroups>
Expand Down Expand Up @@ -552,6 +561,9 @@
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="HorizontalThumb" Storyboard.TargetProperty="(primitives:ScrollBarThumbHelper.IsExpanded)">
<DiscreteBooleanKeyFrame KeyTime="0:0:0.5" Value="True" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</Border.Resources>
<VisualStateManager.VisualStateGroups>
Expand Down

0 comments on commit 289113b

Please sign in to comment.