Skip to content

Latest commit

 

History

History
76 lines (44 loc) · 6.3 KB

slider.md

File metadata and controls

76 lines (44 loc) · 6.3 KB
-api-id -api-type
T:Windows.UI.Xaml.Controls.Slider
winrt class

Windows.UI.Xaml.Controls.Slider

-description

Represents a control that lets the user select from a range of values by moving a Thumb control along a track.

-xaml-syntax

<Slider .../>

-remarks

Tip

For more info, design guidance, and code examples, see Sliders.

Slider is a control that lets the user select from a range of values by moving a Thumb control along a track.

Slider control

Use a Slider control when you want your users to be able to set defined, contiguous values (such as volume or brightness) or a range of discrete values (such as screen resolution settings). Sliders are for user interaction. If a user can't ever change the value, use read-only text instead. For more information on when to use a Slider, see Guidelines for sliders.

Binding Minimum and Maximum values

When binding Minimum and Maximum values in Extensible Application Markup Language (XAML), declare the Binding for Maximum first. If the Binding for Maximum is declared after Minimum, the bound value for Maximum is ignored and the following situations can occur:

To avoid this behavior, declare the Binding for Maximum first in your Extensible Application Markup Language (XAML).

These behaviors can also occur if you set the Minimum value without also explicitly setting the Maximum value.

Control style and template

You can modify the default Style and ControlTemplate to give the control a unique appearance. For information about modifying a control's style and template, see Styling controls. The default style, template, and resources that define the look of the control are included in the generic.xaml file. For design purposes, generic.xaml is available locally with the SDK or NuGet package installation.

  • WinUI Styles (recommended): For updated styles from WinUI, see \Users\<username>\.nuget\packages\microsoft.ui.xaml\<version>\lib\uap10.0\Microsoft.UI.Xaml\Themes\generic.xaml.
  • Non-WinUI styles: For built-in styles, see %ProgramFiles(x86)%\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\<SDK version>\Generic\generic.xaml.

Locations might be different if you customized the installation. Styles and resources from different versions of the SDK might have different values.

XAML also includes resources that you can use to modify the colors of a control in different visual states without modifying the control template. Modifying these resources is preferred to setting properties such as Background and Foreground. For more info, see the Light-weight styling section of the XAML styles article. Light-weight styling resources are available starting in Windows 10, version 1607 (SDK 14393).

-examples

Tip

For more info, design guidance, and code examples, see Slider.

[!div class="nextstepaction"] Open the WinUI 2 Gallery app and see the Slider in action

The WinUI 2 Gallery app includes interactive examples of most WinUI 2 controls, features, and functionality. Get the app from the Microsoft Store or get the source code on GitHub.

The following code example shows several slider controls and how to handle the ValueChanged event. The ValueChanged event is used to update the value of a TextBlock as the Value property of the slider changes.

[!code-xaml1]

[!code-csharp11]

[!code-vb11]

-see-also

Sliders overview, RangeBase, ComboBox, ListBox, Controls list, Controls by function