I would like to prevent selection of ListBoxItems in my ListBox. My DataTemplate has a checkbox and this should be the only thing the user can click or select. How can I do that? Thanks!
A:
When your user will try to (un)check your checkboxes then item become 'active' in some way. And focused style will be applied. As far as i know there is no way to disable selection(because if you did your checkboxes will not work) but you can override focused(or selected) style of your listbox items
Trickster
2009-09-30 07:36:12
Using ItemsCOntrol, like Drew says, does the trick.
Gustavo Cavalcanti
2009-09-30 16:01:18
+4
A:
This is almost a duplicate question. In fact, you're asking two questions here:
Either style your
ListBoxItem
so that it doesn't show selection (look elsewhere on SO for that answer), or replaceListBox
withItemsControl
if you don't need the other features thatListBox
provides.Bind your checkbox's IsChecked property to the parent
ListBoxItem.IsSelected
property:<CheckBox IsChecked="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}, Path=IsSelected}" />
Drew Noakes
2009-09-30 07:51:58