WPF - prevent ListBox item selection

datatemplate, listbox, wpf

Solution

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 replace `ListBox` with `ItemsControl` if you don't need the other features that `ListBox` provides.

Bind your checkbox's IsChecked property to the parent `ListBoxItem.IsSelected` property:

<CheckBox 
   IsChecked="{Binding
      RelativeSource={RelativeSource Mode=FindAncestor, 
                                     AncestorType=ListBoxItem},
      Path=IsSelected}"
/>

Problem

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!

Original source