C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Value: This returns a double variable. It can be any value between Minimum (default 0) and Maximum (default 10).
DoubleTip: Try setting the Minimum and Maximum properties in your XAML code. These properties can also be set in a C# event handler.
Example markup: XAML
<Window x:Class="WpfApplication13.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Slider HorizontalAlignment="Left"
Margin="10,10,0,0"
VerticalAlignment="Top"
Width="250"
ValueChanged="Slider_ValueChanged"/>
</Grid>
</Window>
Example code: C#
using System.Windows;
using System.Windows.Controls;
namespace WpfApplication13
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Slider_ValueChanged(object sender,
RoutedPropertyChangedEventArgs<double> e)
{
// ... Get Slider reference.
var slider = sender as Slider;
// ... Get Value.
double value = slider.Value;
// ... Set Window Title.
this.Title = "Value: " + value.ToString("0.0") + "/" + slider.Maximum;
}
}
}
Also: Often the Minimum and Maximum attributes need to be adjusted. This can be done in the XAML, or a Slider_Loaded event handler.