Skip to content

Commit 1a83380

Browse files
corvinszCorvin SzimionKeboo
authored
Fix3628 - Slider ToolTip not showing (#3705)
* (WIP) setting IsMoveToPointEnabled to false fixes the issue * set IsMoveToPointEnabled=False in all Slider styles * added a new AP to SliderAssist to add an eventhandler to the RepeatButtons of the Slider * Cleanup of Slider Style and launchSettings * Moving assist to be on the slider itself This allow fixes it when the slider has a background color, or the user clicks on the ticks above/below the track --------- Co-authored-by: Corvin Szimion <[email protected]> Co-authored-by: Kevin Bost <[email protected]>
1 parent 5015fdf commit 1a83380

File tree

3 files changed

+57
-10
lines changed

3 files changed

+57
-10
lines changed

src/MaterialDesignThemes.Wpf/SliderAssist.cs

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace MaterialDesignThemes.Wpf;
1+
using System.Windows.Media;
2+
3+
namespace MaterialDesignThemes.Wpf;
24

35
public static class SliderAssist
46
{
@@ -21,22 +23,62 @@ public static readonly DependencyProperty OnlyShowFocusVisualWhileDraggingProper
2123
typeof(SliderAssist),
2224
new PropertyMetadata(false));
2325

24-
public static void SetOnlyShowFocusVisualWhileDragging(RangeBase element, bool value)
25-
=> element.SetValue(OnlyShowFocusVisualWhileDraggingProperty, value);
26-
2726
public static bool GetOnlyShowFocusVisualWhileDragging(RangeBase element)
2827
=> (bool)element.GetValue(OnlyShowFocusVisualWhileDraggingProperty);
2928

29+
public static void SetOnlyShowFocusVisualWhileDragging(RangeBase element, bool value)
30+
=> element.SetValue(OnlyShowFocusVisualWhileDraggingProperty, value);
31+
3032
public static readonly DependencyProperty ToolTipFormatProperty
3133
= DependencyProperty.RegisterAttached(
3234
"ToolTipFormat",
3335
typeof(string),
3436
typeof(SliderAssist),
3537
new PropertyMetadata(null));
3638

39+
public static string GetToolTipFormat(RangeBase element)
40+
=> (string)element.GetValue(ToolTipFormatProperty);
41+
3742
public static void SetToolTipFormat(RangeBase element, string value)
3843
=> element.SetValue(ToolTipFormatProperty, value);
3944

40-
public static string GetToolTipFormat(RangeBase element)
41-
=> (string)element.GetValue(ToolTipFormatProperty);
45+
// Fix for Issue3628
46+
public static readonly DependencyProperty FocusSliderOnClickProperty =
47+
DependencyProperty.RegisterAttached(
48+
"FocusSliderOnClick",
49+
typeof(bool),
50+
typeof(SliderAssist),
51+
new PropertyMetadata(false, OnFocusSliderOnClickChanged));
52+
53+
public static bool GetFocusSliderOnClick(RangeBase obj) =>
54+
(bool)obj.GetValue(FocusSliderOnClickProperty);
55+
56+
public static void SetFocusSliderOnClick(RangeBase obj, bool value) =>
57+
obj.SetValue(FocusSliderOnClickProperty, value);
58+
59+
private static void OnFocusSliderOnClickChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
60+
{
61+
if (d is Slider slider)
62+
{
63+
if ((bool)e.NewValue)
64+
{
65+
slider.AddHandler(UIElement.PreviewMouseLeftButtonDownEvent,
66+
(MouseButtonEventHandler)Slider_PreviewMouseLeftButtonDown,
67+
true);
68+
}
69+
else
70+
{
71+
slider.RemoveHandler(UIElement.PreviewMouseLeftButtonDownEvent,
72+
(MouseButtonEventHandler)Slider_PreviewMouseLeftButtonDown);
73+
}
74+
}
75+
}
76+
77+
private static void Slider_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
78+
{
79+
if (sender is Slider slider)
80+
{
81+
slider.Focus();
82+
}
83+
}
4284
}

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Slider.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters"
44
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf">
@@ -993,6 +993,7 @@
993993
<Setter Property="Template" Value="{StaticResource MaterialDesignDiscreteSliderHorizontal}" />
994994
<Setter Property="UseLayoutRounding" Value="False" />
995995
<Setter Property="wpf:ElevationAssist.Elevation" Value="Dp1" />
996+
<Setter Property="wpf:SliderAssist.FocusSliderOnClick" Value="True" />
996997
<Style.Triggers>
997998
<Trigger Property="IsEnabled" Value="False">
998999
<Setter Property="Foreground" Value="{DynamicResource MaterialDesign.Brush.CheckBox.Disabled}" />
@@ -1015,6 +1016,7 @@
10151016
<Setter Property="Template" Value="{StaticResource MaterialDesignDiscreteSliderVertical}" />
10161017
<Setter Property="UseLayoutRounding" Value="False" />
10171018
<Setter Property="wpf:ElevationAssist.Elevation" Value="Dp1" />
1019+
<Setter Property="wpf:SliderAssist.FocusSliderOnClick" Value="True" />
10181020
<Style.Triggers>
10191021
<Trigger Property="IsEnabled" Value="False">
10201022
<Setter Property="Foreground" Value="{DynamicResource MaterialDesign.Brush.CheckBox.Disabled}" />

tests/MaterialDesignThemes.UITests/WPF/TextBoxes/TextBoxTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,12 @@ public async Task ContextMenu_FollowsTextBoxFontFamily()
318318

319319
var contextMenu = await textBox.GetElement<ContextMenu>(".ContextMenu");
320320

321-
var textBoxFont = await textBox.GetFontFamily();
322-
Assert.Equal("Times New Roman", textBoxFont?.FamilyNames.Values.First());
323-
Assert.Equal(textBoxFont, await contextMenu.GetFontFamily());
321+
FontFamily? textBoxFont = await textBox.GetFontFamily();
322+
Assert.Contains("Times New Roman", textBoxFont?.FamilyNames.Values ?? []);
323+
await Wait.For(async () =>
324+
{
325+
Assert.Equal(textBoxFont, await contextMenu.GetFontFamily());
326+
});
324327

325328
recorder.Success();
326329
}

0 commit comments

Comments
 (0)