Code:
private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
updateTickCounter(slider1.Value);
}
private void updateTickCounter(double value)
{
tickCounter.Content = value.ToString();
}
XAML:
<Slider Height="32" HorizontalAlignment="Right" Margin="0,21,61,0" Name="slider1" VerticalAlignment="Top" Width="200" IsSnapToTickEnabled="True" Orientation="Horizontal" TickFrequency="1" TickPlacement="BottomRight" Value="1" Minimum="1" Maximum="10" ValueChanged="slider1_ValueChanged" />
I’m trying to have a slider that starts at value 1 out of 10. Every time the slider is moved I want a label called ‘tickCounter’ to change text.
The code above throws an exception when ran — “Object reference not set to an instance of an object.”
However, once I change both the values of “Value” and “Minimum” in XAML it works fine. It’s as if I can’t make it not start at zero. It’s really weird. Any help?
If I look on stack trace provided, then only possible reason of nullexception seems to me is that tickCounter==null