The Slider control has a property "AutoToolTip" that I prefer, which can display the current scale during dragging. However, this scale does not support template customization, and even custom formats are not possible. This greatly limits its scope of use. An article online solved this problem and can realize custom display format
The code is as follows:
/// <summary> /// A Slider which provides a way to modify the /// auto tooltip text by using a format string. /// </summary> public class FormattedSlider : Slider { private ToolTip _autoToolTip; private string _autoToolTipFormat; /// <summary> /// Gets/sets a format string used to modify the auto tooltip's content. /// Note: This format string must contain exactly one placeholder value, /// which is used to hold the tooltip's original content. /// </summary> public string AutoToolTipFormat { get { return _autoToolTipFormat; } set { _autoToolTipFormat = value; } } protected override void OnThumbDragStarted(DragStartedEventArgs e) { (e); (); } protected override void OnThumbDragDelta(DragDeltaEventArgs e) { (e); (); } private void FormatAutoToolTipContent() { if (!()) { = ( , ); } } private ToolTip AutoToolTip { get { if (_autoToolTip == null) { FieldInfo field = typeof(Slider).GetField( "_autoToolTip", | ); _autoToolTip = (this) as ToolTip; } return _autoToolTip; } } }
It's also very easy to use.
<local:FormattedSlider AutoToolTipFormat="{}{0}% used" AutoToolTipPlacement="BottomRight" />
In fact, the principle is not complicated. Set the "_autoToolTip" variable by reflecting it to realize the custom AutoToolTip format.
private ToolTip AutoToolTip { get { if (_autoToolTip == null) { FieldInfo field = typeof(Slider).GetField( "_autoToolTip", | ); _autoToolTip = (this) as ToolTip; } return _autoToolTip; } }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.