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

Add tooltip text converter to RangeSlider #1833

Merged
merged 1 commit into from
Mar 12, 2015
Merged
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
25 changes: 23 additions & 2 deletions MahApps.Metro/Controls/RangeSlider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Threading;

Expand Down Expand Up @@ -233,6 +234,10 @@ public event DragDeltaEventHandler CentralThumbDragDelta
DependencyProperty.Register("AutoToolTipPrecision", typeof (Int32), typeof (RangeSlider),
new FrameworkPropertyMetadata(0), IsValidPrecision);

public static readonly DependencyProperty AutoToolTipTextConverterProperty =
DependencyProperty.Register("AutoToolTipTextConverter", typeof (IValueConverter), typeof (RangeSlider),
new FrameworkPropertyMetadata(null));

public static readonly DependencyProperty IntervalProperty =
DependencyProperty.Register("Interval", typeof(Int32), typeof(RangeSlider),
new FrameworkPropertyMetadata(100, IntervalChangedCallback), IsValidPrecision);
Expand All @@ -258,6 +263,16 @@ public Int32 AutoToolTipPrecision
set { SetValue(AutoToolTipPrecisionProperty, value); }
}

/// <summary>
/// Get/sets the converter for the tooltip text
/// </summary>
[Bindable(true), Category("Behavior")]
public IValueConverter AutoToolTipTextConverter
{
get { return (IValueConverter)GetValue(AutoToolTipTextConverterProperty); }
set { SetValue(AutoToolTipTextConverterProperty, value); }
}

/// <summary>
/// Get/sets tooltip, which will show while dragging thumbs and display currect value
/// </summary>
Expand Down Expand Up @@ -2143,15 +2158,21 @@ private Boolean IsDoubleCloseToInt(double val)
//Get lower value for autotooltip
private String GetLowerToolTipNumber()
{
NumberFormatInfo format = (NumberFormatInfo) (NumberFormatInfo.CurrentInfo.Clone());
if (AutoToolTipTextConverter != null)
return AutoToolTipTextConverter.Convert(LowerValue, typeof(string), null, CultureInfo.InvariantCulture).ToString();

NumberFormatInfo format = (NumberFormatInfo)(NumberFormatInfo.CurrentInfo.Clone());
format.NumberDecimalDigits = AutoToolTipPrecision;
return LowerValue.ToString("N", format);
}

//Get upper value for autotooltip
private String GetUpperToolTipNumber()
{
NumberFormatInfo format = (NumberFormatInfo) (NumberFormatInfo.CurrentInfo.Clone());
if (AutoToolTipTextConverter != null)
return AutoToolTipTextConverter.Convert(UpperValue, typeof(string), null, CultureInfo.InvariantCulture).ToString();

NumberFormatInfo format = (NumberFormatInfo)(NumberFormatInfo.CurrentInfo.Clone());
format.NumberDecimalDigits = AutoToolTipPrecision;
return UpperValue.ToString("N", format);
}
Expand Down