Parse error.Primitives.RangeBase.Minimum

1

I'm trying to put a slider on a windows universal 8.1 and I'm uncertain what is needed. My error is:

Exception thrown: 'Windows.UI.Xaml.Markup.XamlParseException' in Mead Must Maker.Windows.exe
WinRT information: Failed to assign to property 'Windows.UI.Xaml.Controls.Primitives.RangeBase.Minimum'. [Line: 22 Position: 182]
The program '[1260] Mead Must Maker.Windows.exe' has exited with code -1073741189 (0xc000027b). 

What exactly is going wrong with this code? This is line 22:

<Slider x:Name="volumeSlider" HorizontalAlignment="Left" Height="50" Margin="50,400,0,0" VerticalAlignment="Top" Width="550" Maximum="10" LargeChange="1" Minimum="1" SmallChange="0.5" StepFrequency="0.5" TickFrequency="1" TickPlacement="Outside" Value="5" FontFamily="Global User Interface" ValueChanged="volumeSlider_ValueChanged"/>

Here's the Event Handler:

private void volumeSlider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
    {
        volume = float.Parse(volumeSlider.Value.ToString());
        volumeTextBox.Text = volume.ToString();
        Calculate();
    }
c#
slider
xamlparseexception
windows-8.1-universal
asked on Stack Overflow Sep 10, 2016 by StabbednHacked • edited Sep 10, 2016 by StabbednHacked

1 Answer

0

There are some problems in your code. The following is your code from MainPage.xaml:

...Value="5" FontFamily="Global User Interface" ValueChanged="volumeSlider_ValueChanged"/>

In Slider control you set Value="5" and ValueChanged="volumeSlider_ValueChanged", notice that the code Value="5" will cause the function(volumeSlider_ValueChanged) to run immediately, but the Slider instance haven't been created at this moment. So if you debug your volumeSlider_ValueChanged function you can find the volumeSlider is null reference and it will cause a NullException. You can adjust you code like this:

private void volumeSlider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
        {
            if (volumeSlider != null) {
                var volume = float.Parse(volumeSlider.Value.ToString());
                volumeTextBox.Text = volume.ToString();
            }
        }
answered on Stack Overflow Sep 14, 2016 by DV8DUG

User contributions licensed under CC BY-SA 3.0