How to get TreeView SelectedItem/Value?
-
I have Multiple Lists that are bound to multiple TreeViewItems within the Tree as in the code below. This is working perfectly to display the bound items; however, I couldn't figure out how to get the selected item value. For example, if the user clicks the color Blue, I would like to be able to get that value, in this case "Blue," in order to be able to bind to a property in the ViewModel
-
I have Multiple Lists that are bound to multiple TreeViewItems within the Tree as in the code below. This is working perfectly to display the bound items; however, I couldn't figure out how to get the selected item value. For example, if the user clicks the color Blue, I would like to be able to get that value, in this case "Blue," in order to be able to bind to a property in the ViewModel
Are you only going one way? UI -> VM? If so, there is a SelectedItem bindable property on the TreeView that you can use. If you want two-way binding (set the selection from the VM), that is a lot more work.
-
I have Multiple Lists that are bound to multiple TreeViewItems within the Tree as in the code below. This is working perfectly to display the bound items; however, I couldn't figure out how to get the selected item value. For example, if the user clicks the color Blue, I would like to be able to get that value, in this case "Blue," in order to be able to bind to a property in the ViewModel
-
Are you only going one way? UI -> VM? If so, there is a SelectedItem bindable property on the TreeView that you can use. If you want two-way binding (set the selection from the VM), that is a lot more work.
-
It is binding from UI to VM. I just need to get the value of the selecteditem, and the SelectedItem of the TreeView is Read Only. So how do I get the Value of the Selected Item? Thanks in advance.
So what is the issue? SelectedItem contains your selected item. It is only read only to you. The TreeView control sets internally. You do need to use one way binding though.
-
I have Multiple Lists that are bound to multiple TreeViewItems within the Tree as in the code below. This is working perfectly to display the bound items; however, I couldn't figure out how to get the selected item value. For example, if the user clicks the color Blue, I would like to be able to get that value, in this case "Blue," in order to be able to bind to a property in the ViewModel
Why can't you just bind SelectedItem from the TreeView to your VM ?