Share via


Slider Constructors

Definition

Overloads

Name Description
Slider()

Initializes a new instance of the Slider class with default minimum (0) and maximum (1) values.

Slider(Double, Double, Double)

Initializes a new instance of the Slider class with specified minimum, maximum, and initial values.

Slider()

Source:
Slider.cs
Source:
Slider.cs
Source:
Slider.cs
Source:
Slider.cs

Initializes a new instance of the Slider class with default minimum (0) and maximum (1) values.

public:
 Slider();
public Slider();
Public Sub New ()

Remarks

The following example shows a basic use.

using System;
using Microsoft.Maui.Controls;

namespace FormsGallery
{
    class SliderDemoPage : ContentPage
    {
        Label label;

        public SliderDemoPage()
        {
            Label header = new Label
            {
                Text = "Slider",
                Font = Font.BoldSystemFontOfSize(50),
                HorizontalOptions = LayoutOptions.Center
            };

            Slider slider = new Slider
            {
                Minimum = 0,
                Maximum = 100,
                VerticalOptions = LayoutOptions.CenterAndExpand
            };
            slider.ValueChanged += OnSliderValueChanged;

            label = new Label
            {
                Text = "Slider value is 0",
                Font = Font.SystemFontOfSize(NamedSize.Large),
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.CenterAndExpand
            };

            // Accomodate iPhone status bar.
            this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);

            // Build the page.
            this.Content = new StackLayout
            {
                Children =
                {
                    header,
                    slider,
                    label
                }
            };
        }

        void OnSliderValueChanged(object sender, ValueChangedEventArgs e)
        {
            label.Text = String.Format("Slider value is {0:F1}", e.NewValue);
        }
    }
}

Applies to

Slider(Double, Double, Double)

Source:
Slider.cs
Source:
Slider.cs
Source:
Slider.cs
Source:
Slider.cs

Initializes a new instance of the Slider class with specified minimum, maximum, and initial values.

public:
 Slider(double min, double max, double val);
public Slider(double min, double max, double val);
new Microsoft.Maui.Controls.Slider : double * double * double -> Microsoft.Maui.Controls.Slider
Public Sub New (min As Double, max As Double, val As Double)

Parameters

min
Double

The minimum value of the slider.

max
Double

The maximum value of the slider.

val
Double

The initial value of the slider, clamped between min and max.

Exceptions

Thrown when min is greater than or equal to max.

Applies to