The slider control has an attribute "autotooltip" that I like most. The current scale can be displayed during the drag process. However, this scale does not support template customization, and even the custom format does not work. This greatly limits the scope of use. There is an article on the Internet that modifying the auto tooltip of a slider (this address cannot be accessed due to WordPress being harmonious) solves this problem and allows you to customize the display format.
The Code is as follows:
Code
/** // <Summary>
/// A slider which provides a way to modify
/// 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)
{
Base. onthumbdragstarted (E );
This. formatautotooltipcontent ();
}
Protected override void onthumbdragdelta (dragdeltaeventargs E)
{
Base. onthumbdragdelta (E );
This. formatautotooltipcontent ();
}
Private void formatautotooltipcontent ()
{
If (! String. isnullorempty (this. autotooltipformat ))
{
This. autotooltip. content = string. Format (
This. autotooltipformat,
This. autotooltip. content );
}
}
Private tooltip autotooltip
{
Get
{
If (_ autotooltip = NULL)
{
Fieldinfo field = typeof (slider). getfield (
"_ Autotooltip ",
Bindingflags. nonpublic | bindingflags. instance );
_ Autotooltip = field. getvalue (this) as tooltip;
}
Return _ autotooltip;
}
}
}
It is easy to use.
<Local: formattedslider
Autotooltipformat = "{}{ 0} % used"
Autotooltipplacement = "bottomright"/>
In fact, the principle is not complex. You can set the "_ autotooltip" variable through reflection to customize the autotooltip format.
Private tooltip autotooltip
{
Get
{
If (_ autotooltip = NULL)
{
Fieldinfo field = typeof (slider). getfield (
"_ Autotooltip ",
Bindingflags. nonpublic | bindingflags. instance );
_ Autotooltip = field. getvalue (this) as tooltip;
}
Return _ autotooltip;
}
}