0

We have 6 CheckBoxes on a user control. We want to be able to determine, whether or not each of the 6 boxes are checked. We tried doing this in this event in the code behind:

private const short Black = 1;
private const short White = 32;
private const short Asian = 2;
private const short Islander = 8;
private const short AmInd = 4;
private const short Alask = 16;

private void RaceCheckboxes_Checked(object sender, System.Windows.RoutedEventArgs e)
{
    short race = 0;

    if (cbAlask.IsChecked == true)
    {
        race += Alask;
    }
    if (cbAmInd.IsChecked == true)
    {
        race += AmInd;
    }
    if (cbIslander.IsChecked == true)
    {
        race += Islander;
    }
    if (cbAsian.IsChecked == true)
    {
        race += Asian;
    }
    if (cbWht.IsChecked == true)
    {
        race += White;
    }
    if (cbBlack.IsChecked == true)
    {
        race += Black;
    }

    atr.Race = race;
}

The thing I don't understand is this. When the user clicks on the checkbox named cbWht, it entered this event and all 6 of the checkboxes IsChecked property were true. Why is that? Only 1 of them was checked.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Rod
  • 4,107
  • 12
  • 57
  • 81

1 Answers1

0

Try using the Clicked event instead of the Checked event. I.e. RaceCheckboxes_Clicked.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Chris Bennet
  • 587
  • 5
  • 13
  • What's the difference between the Clicked and the Checked events, as far as the Checkbox in WPF goes? – Rod Jun 05 '13 at 00:36