How can I prevent a ToggleButton from being Toggled without setting IsEnabled=False

Posted by Bryan Anderson on Stack Overflow See other posts from Stack Overflow or by Bryan Anderson
Published on 2010-03-30T21:25:58Z Indexed on 2010/06/15 19:22 UTC
Read the original article Hit count: 236

Filed under:
|

I have a list of ToggleButtons being used as the ItemTemplate in a ListBox similar to this answer using the MultiSelect mode of the Listbox. However I need to make sure at least one item is always selected.

I can get the proper behavior from the ListBox by just adding an item back into the ListBox's SelectedItems collection on the ListBox.SelectionChanged event but my ToggleButton still moves out of its toggled state so I think I need to stop it earlier in the process.

I would like to do it without setting IsEnabled="False" on the last button Selected because I'd prefer to stay with the Enabled visual style without having to redo my button templates. Any ideas?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about togglebutton