0

I've found a strange thing about RadioButton in the WPF. I can put radio button to one component and select another component at the same time. Like on the screenshot.

How can I fix that?

If I don't select any component like in the second string, then next code give me an error:

MessageBox.Show(ListBox1.SelectedItem.ToString());

enter image description here

Amazing User
  • 3,473
  • 10
  • 36
  • 75

1 Answers1

1

Selecting a ListBoxItem, and setting the Checked property of a RadioButton are two totally different actions.

Thus, you can check one radio button, and have a different list box item selected. If you don't have any list box items selected, trying to access SelectedItem will throw as you have found.

The basic answer is that you probably don't want to select the list box items. Set the SelectionMode to None. To find the checked radio button, consider using a ValueEqualsConverter

Community
  • 1
  • 1
BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117