I am new to WPF and am having issues with associating a value with an object. I have a TreeView with CheckBoxes and I am wondering how I can associate an object to each checkbox. I want to be able to select all the checked checkboxes (no problem) and get a list of objects that are associated with each checked box.
For example, let's say I have a class called Fruit that has properties DisplayName and Price
TreeView:
- Mango
- ✓ Apple
- Orange
I want to be able to return the Apple object so that I can get the Price and other properties associated to the Fruit.
Here is a code sample for me adding checkboxes to the TreeView
TreeViewItem treeViewItem = new TreeViewItem();
CheckBox chkBox = new CheckBox();
chkBox.IsChecked = false;
chkBox.Content = "Value";
chkBox.IsThreeState = false;
chkBox.Click += chkBox_Click;
treeViewItem.Header = chkBox;