Skip to content
Open
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 components/RangeSelector/src/RangeSelector.Input.Drag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void Thumb_DragStarted(Thumb thumb)

if (_toolTip != null)
{
if (Orientation == Orientation.Vertical && VerticalToolTipPlacement == VerticalToolTipPlacement.None)
if (!IsThumbToolTipEnabled || (Orientation == Orientation.Vertical && VerticalToolTipPlacement == VerticalToolTipPlacement.None))
{
_toolTip.Visibility = Visibility.Collapsed;
}
Expand Down
1 change: 1 addition & 0 deletions components/RangeSelector/src/RangeSelector.Input.Key.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private void MaxThumb_KeyDown(object sender, KeyRoutedEventArgs e)

private void ShowToolTip()
{
if (!IsThumbToolTipEnabled) return;
var isHorizontal = Orientation == Orientation.Horizontal;
if (!isHorizontal && VerticalToolTipPlacement == VerticalToolTipPlacement.None) return;
if (_toolTip != null)
Expand Down
46 changes: 46 additions & 0 deletions components/RangeSelector/src/RangeSelector.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,26 @@ public partial class RangeSelector : Control
typeof(RangeSelector),
new PropertyMetadata(VerticalToolTipPlacement.Right));

/// <summary>
/// Identifies the <see cref="IsThumbToolTipEnabled"/> property.
/// </summary>
public static readonly DependencyProperty IsThumbToolTipEnabledProperty =
DependencyProperty.Register(
nameof(IsThumbToolTipEnabled),
typeof(bool),
typeof(RangeSelector),
new PropertyMetadata(true));

/// <summary>
/// Identifies the <see cref="ThumbToolTipValueConverter"/> property.
/// </summary>
public static readonly DependencyProperty ThumbToolTipValueConverterProperty =
DependencyProperty.Register(
nameof(ThumbToolTipValueConverter),
typeof(IValueConverter),
typeof(RangeSelector),
new PropertyMetadata(null));

/// <summary>
/// Gets or sets the absolute minimum value of the range.
/// </summary>
Expand Down Expand Up @@ -164,6 +184,32 @@ public VerticalToolTipPlacement VerticalToolTipPlacement
set => SetValue(VerticalToolTipPlacementProperty, value);
}

/// <summary>
/// Gets or sets a value that indicates whether a tooltip that displays the current value
/// is shown for the min and max thumbs.
/// </summary>
/// <value>
/// true if a tooltip is shown for the min and max thumbs; otherwise, false. The default is true.
/// </value>
public bool IsThumbToolTipEnabled
{
get => (bool)GetValue(IsThumbToolTipEnabledProperty);
set => SetValue(IsThumbToolTipEnabledProperty, value);
}

/// <summary>
/// Gets or sets a custom <see cref="IValueConverter"/> to be used for the tooltip text conversion
/// when <see cref="IsThumbToolTipEnabled"/> is set to true.
/// </summary>
/// <value>
/// The converter used to convert the thumb value to a display string. The default is null.
/// </value>
public IValueConverter ThumbToolTipValueConverter
{
get => (IValueConverter)GetValue(ThumbToolTipValueConverterProperty);
set => SetValue(ThumbToolTipValueConverterProperty, value);
}

private static void OrientationChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var rangeSelector = d as RangeSelector;
Expand Down
4 changes: 3 additions & 1 deletion components/RangeSelector/src/RangeSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ private static void UpdateToolTipText(RangeSelector rangeSelector, TextBlock too
{
if (toolTip != null)
{
toolTip.Text = string.Format("{0:0.##}", newValue);
var converter = rangeSelector.ThumbToolTipValueConverter;
var convertedText = converter?.Convert(newValue, typeof(string), null, string.Empty) as string;
toolTip.Text = convertedText ?? string.Format("{0:0.##}", newValue);
}
}

Expand Down