I feel like this should be a simple feature but I don't know how to bind to the selected items in a Listbox without using code behind.
I have a Listbox with Datatemplate containing a Checkbox. I want to get the list of the checked/selected items. How do I do this?
If I cannot get the SelectedItems, I want to bind to something that triggers "SelectedProduct" every time something gets selected so I can iterate through the "ProductList" and find the checked items. However, SelectedItem does not trigger every time I click on an item.
Here is my code:
<ListBox ItemsSource="{Binding ProductList}" SelectedItem="{Binding SelectedProduct}" SelectionMode="Multiple">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay}" Content="{Binding ID}" Margin="2"/>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="IsSelected" Value="{Binding Mode=TwoWay, Path=IsChecked}"/>
</Style>
</ListBox.ItemContainerStyle>