I am having the strangest problem, and I have to be missing something.
Here is my code that is causing the error.
if (radLot.Checked == true)
{
S
Checked is the name of the event that is raised when a ToggleButton
is checked. (The RadioButton
class derives from ToggleButton
.)
I assume you want to access the IsChecked property, which gets (or sets) whether the ToggleButton
is checked.
if (radLot.IsChecked == true)
{
SymbolSpecification = "LotRenderer";
}
Hint: Most boolean properties related to the visual state start with Is—
in WPF.
Alternative you can check the CheckState to perform your statement.
if (radLot.CheckState == CheckState.Checked)
{
}
Edit: This will only work when writing a winform application. It will not work with WPF. Use Douglas' answer for WPF.
This is indeed true - just hit this problem myself converting from Winforms
to WPF
.
In WPF
using:
if (radiobutton1.IsChecked == true)
works
BUT
if (radiobutton1.IsChecked)
Does not.
However in WinForms
if (radiobutton1.Checked)
works but does not in WPF
.