I am using Data Templates to set the values of checkboxes within a combobox as such:
<ComboBox Margin="118,117,163,164" ItemsSource="{Binding collection}">
<ComboBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
This works as it should. My problem is, when the user checks the box, I need to be able to get the content value stored within the checkbox. Is this possible?
Thanks.
You need to bind the Checkbox’s IsChecked property to another property on the backing object for each item. i.e. the type which has the Name should expose a boolean property IsSelected.
Databinding will update the IsSelected property appropriately, which would be easy for you to access in code. e.g. you can loop over the list and filter all the items that have IsSelected = false.
Code Sample
XAML
Code-behind