UWP Slider
The Slider class represents a control that lets the UWP app users select
from a range of values by moving a Thumb control along a track. The RangeBase
class’s ValueChanged event occurs when the range value changes. The UWP
developers can use this event to respond to the Slider value changes.
The RangeBase class’s Maximum property gets or sets the highest possible value of the range element such as Slider control. This property value type is Doublewhich is the highest possible value of the range element. The default value of this property is 1.
The RangeBase class’s Minimum property gets or sets the minimum possible value of the range element. This property value type is also Double which is the minimum possible value of the range element. The default value of the Minimum property is 0.
The Slider class’s TickFrequency property gets or sets the increment of the value range that ticks should be created for. This property value type is Double which is the increment to create tick marks for. The default value of the TickFrequency property is 0.0.
The following UWP app development tutorial code will demonstrate how we can use a Slider control in our app and how we can handle the ValueChanged event to respond to the Slider value changes. Here we also demonstrate how to set the minimum and maximum value for the Slider control and how to define the tick position.
The RangeBase class’s Maximum property gets or sets the highest possible value of the range element such as Slider control. This property value type is Doublewhich is the highest possible value of the range element. The default value of this property is 1.
The RangeBase class’s Minimum property gets or sets the minimum possible value of the range element. This property value type is also Double which is the minimum possible value of the range element. The default value of the Minimum property is 0.
The Slider class’s TickFrequency property gets or sets the increment of the value range that ticks should be created for. This property value type is Double which is the increment to create tick marks for. The default value of the TickFrequency property is 0.0.
The following UWP app development tutorial code will demonstrate how we can use a Slider control in our app and how we can handle the ValueChanged event to respond to the Slider value changes. Here we also demonstrate how to set the minimum and maximum value for the Slider control and how to define the tick position.
MainPage.xaml
<Page
x:Class="UniversalAppTutorials.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UniversalAppTutorials"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel
x:Name="stack_panel1"
Margin="50"
Orientation="Vertical"
Background="PaleVioletRed"
Padding="35"
>
<TextBlock
x:Name="text_block1"
Text="Darg the slider thumb to change this text size."
TextWrapping="Wrap"
/>
<Slider
x:Name="slider1"
Maximum="45"
Minimum="25"
TickFrequency="5"
TickPlacement="BottomRight"
ValueChanged="Slider1_ValueChanged"
Orientation="Horizontal"
/>
</StackPanel>
</Page>
MainPage.xaml.cs
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
namespace UniversalAppTutorials
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void Slider1_ValueChanged(object sender, RangeBaseValueChangedEventArgs e) {
// Get the slider instance
Slider slider = sender as Slider;
if (slider != null) {
// Set the text block text size as slider value
text_block1.FontSize = slider.Value;
}
}
}
}

