For WPF in XAML:
<code> <Slider Minimum = 0 Maximum = 100 Value = 50 /> </code>
Minimum - the minimum value, Maximum - respectively, the maximum, Value - the starting value during initialization. Accordingly, with these parameters, you can use the mechanism of binding.
In windows forms, Slider is called TrackBar and has the same fields for controlling it (Minimum, Maximum, Value).
Here is an example Slider-a from my application:
<Slider Grid.Column="1" VerticalAlignment="Center" BorderBrush="Black" BorderThickness="1" Maximum="{Binding Path=ModelMainWindow.SliderMaximum}" Minimum="{Binding Path=ModelMainWindow.SliderMinimum}" Thumb.DragCompleted="Slider_DragCompleted" Thumb.DragStarted="Slider_DragStarted" Value="{Binding Path=ModelMainWindow.SliderValue, Mode=TwoWay}" />
This is in model:
/// <summary> /// Represent minimum slider position /// </summary> public double SliderMinimum { get { return _sliderMinimum; } set { _sliderMinimum = value; NotifyPropertyChanged(); } } /// <summary> /// Represent maximum slider position /// </summary> public double SliderMaximum { get { return _sliderMaximum; } set { _sliderMaximum = value; NotifyPropertyChanged(); } } /// <summary> /// Represent current slider position /// </summary> public double SliderValue { get { return _sliderValue; } set { _sliderValue = value; NotifyPropertyChanged(); } }
This is the class that implements the INPC (INotifyPropertyChanged) interface:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; namespace MP3_Player.Model { public class BaseModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected virtual void NotifyPropertyChanged([CallerMemberName]string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } }
I already inherit my model from it, where I use the implementation of this interface