Events in .NET MAUI Slider (SfSlider)
14 Apr 20225 minutes to read
This section explains about how to add the events for slider.
Handle callbacks
- ValueChangeStart - Called when the user selecting a new value for the slider by tap/mouse down in the thumb.
- ValueChanging - Called when the user is selecting a new value for the slider by dragging the thumb.
- ValueChanged - Called when the user completed selecting a new value.
- ValueChangeEnd - Called when the user stopped interacting with slider by tap/mouse up the thumb.
<sliders:SfDateTimeSlider Minimum="2010-01-01"
Maximum="2020-01-01"
Value="2014-01-01"
ValueChangeStart="OnValueChangeStart"
ValueChanging="OnValueChanging"
ValueChanged="OnValueChanged"
ValueChangeEnd="OnValueChangeEnd">
</sliders:SfDateTimeSlider>
{
SfDateTimeSlider slider = new SfDateTimeSlider();
slider.Minimum = new Date(2010, 01, 01);
slider.Maximum = new Date(2020, 01, 01);
slider.value = new Date(2014, 01, 01);
slider.ValueChangeStart += OnValueChanged;
slider.ValueChanging += OnValueChanged;
slider.ValueChanged += OnValueChanged;
slider.ValueChangeEnd += OnValueChanged;
}
private void OnValueChangeStart(object sender, EventArgs e)
{
}
private void OnValueChanging(object sender, SliderValueChangingEventArgs e)
{
}
private void OnValueChanged(object sender, SliderValueChangedEventArgs e)
{
}
private void OnValueChangeEnd(object sender, EventArgs e)
{
}
Customize label text
You can format or change the whole numeric or date label text using the LabelCreated
event. The SliderLabelCreatedEventArgs
contains the following parameters,
- Text – Customize the text color using the
Text
parameter. - Style – Formats the text color, font size, font family, offset using the
Style
parameter.
<sliders:SfSlider Minimum="2"
Maximum="10"
Value="6"
Interval="2"
LabelCreated="OnLabelCreated"
ShowLabels="True">
</sliders:SfSlider>
{
SfSlider slider = new SfSlider();
slider.Minimum = 2;
slider.Maximum = 10;
slider.Value = 6;
slider.Interval = 2;
slider.ShowLabels = true;
sfslider.LabelCreated += OnLabelCreated;
}
private void OnLabelCreated(object sender, SliderLabelCreatedEventArgs e)
{
e.Text = "$" + e.Text;
}
Tooltip text format
By default it is formatted based on NumberFormat
property and DateFormat
property based on whether it is date type SfDateTimeSlider
or numeric SfSlider
.
You can format or change the whole tooltip label text using the TooltipLabelCreated
event. The SliderTooltipLabelCreatedEventArgs
contains the following parameters,
- Text – Change the format of the tooltip text using the
Text
property. - Style – Change the appearance of the tooltip text like color, stroke color, and padding using the
Style
property.
<slider:SfSlider>
<slider:SfSlider.Tooltip>
<slider:SliderTooltip TooltipLabelCreated="OnTooltipLabelCreated"/>
</slider:SfSlider.Tooltip>
</slider:SfSlider>
{
SfSlider slider = new SfSlider();
slider.TooltipLabelCreated += OnTooltipLabelCreated;
}
private void OnTooltipLabelCreated(object sender, SliderTooltipLabelCreatedEventArgs e)
{
e.Text = "$" + e.Text;
}