I have a ToggleButton inside of a ListBox and when that button is clicked I want every other item in the ListBox to be unchecked.
i’m currently trying this
private void ToggleButton_Click(object sender, RoutedEventArgs e)
{
spriteToggleButton _tb = sender as ToggleButton;
for (int i = 0; i < aListBox.Items.Count; i++)
{
ListBoxItem lbi = (ListBoxItem)aListBox.Items[i]; // invalid cast exception here
lbi.IsSelected = false;
}
_tb.IsChecked = true;
}
but I am getting an invalid cast exception.
I would have thought that aListBox.Items[i] would return a ListBoxItem object.
Use a
DataTemplateSince all
RadioButtons will have the sameGroupName, only one will be checked at any time.