(using WPF application)
I get an error when i want to save a bool to a global variable like this:
Window msgOne = new Window();
if (Properties.Settings.Default.sound01 == true)
{
msgOne.radioboxSound.IsChecked = true;
}
else
{
msgOne.radioboxSound.IsChecked = false;
}
msgOne.ShowDialog();
//waiting for close
Properties.Settings.Default.sound01 = msgOne.radioboxSound.IsChecked;
where the radioboxSound is the checkbox, and the Properties.Settings.Default.sound01 is the global parameter that you can make in the settings tab in VB c#
The error that i am getting for the last link of above snipit):
Cannot implicitly convert type “bool?” to “bool”. An explicit conversion exist (are you missing a cast?)
But i don’t have used any bool?, only bolls that have been set.
Anyone know how to deal with this one?
thanx
The radio button’s IsChecked property is a ‘bool?’. Change your code to
A bit more explanation.
Since RadioButton.IsChecked is a Nullable, then regardless of whether the IsThreeState property is set to true or false you will need to handle the fact that IsChecked is nullable.
You could use
or use the null coalescing operator as above.