I just want to create a slider in my C# WPF project and write the value of the slider into a label. I know this is probably really easy to do but I can’t manage to get it working. So here is my slider in my XAML code:
<Slider Height="21" Minimum="-255" Maximum="255" x:Name="sld_brightness" />
<Label x:Name="lb_brightness_nb" />
Now, I try to change the value of the label according to the slider value in my C# code:
public void sld_brightness_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
lb_brightness_nb.Content = (int)sld_brightness.Value;
}
This code does compile but doesn’t do anything. It is not working. What’s wrong?
You could bind it directly; there’s no need to create an event handler for this.
If you want to use the event handler, then it looks like you’re missing the wireup:
Edit
To show only the integer, use an
IValueConverter. Add it to the resources section using<local:DoubleToStringConverter x:Key="DoubleToStringConverter" />.