I have a list of AvailableItems
that I want to display as a list of checkboxes, so that users can pick which items to generate, which are then stored in another lis
I've found a solution to my problem.
I've changed my ItemsControl
to a ListBox
, and added a binding between the SelectedItems with my ItemsToGenerate
collection using the technique described here. It basically allows me to synchronize any custom collection to ListBox.SelectedItems
using a simple attached property.
I'm still able to display this as I initially wanted (a list of checkboxes), by adding a data template to change each ListBoxItem
to a checkbox and binding each Checkbox.IsChecked
to ListBoxItem.IsSelected
.
I had this pattern in so many places in my application that this is the ideal solution for me, because now I just need to specify one attached property, and the rest is all handled by the data bindings, and I don't need any additional code.