I'm trying to show a label based on the selected value of a combo box. I'm using VS2010.
Here's the code:
private void pointsSettings_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (this.pointsSettings.SelectedValue.ToString() == "between")
{
pointsAboveLabel.Visibility = Visibility.Collapsed;
}
else
{
pointsAboveLabel.Visibility = Visibility.Visible;
}
}
And the XAML:
<ComboBox Name="pointsSettings" SelectionChanged="pointsSettings_SelectionChanged">
<ComboBoxItem Content="between" />
<ComboBoxItem Content="above" IsSelected="True" />
<ComboBoxItem Content="below" />
</ComboBox>
<Label Content="points" Name="pointsAboveLabel" />
<Label Content="and" Name="pointsBetweenLabel" Visibility="Collapsed" />
And here is the error I got:
Text reads: "Object reference not set to an instance of an object".
I'm aware that there is another question very similar this - with the same error in fact- however the solution provided (moving a variable initialization to above the InitializeComponent() method call) is not appropriate for me as I have no object initialization.
Any and all help is appreciated most warmly.