问题
I am currently working in UWP and I need to create a TreeView to store hierarchically a query of a service. example: Example I have
I keep the information in a
public ObservableCollection <Model> name_of_object {get; set; } = new ObservableCollection <Model> ();
But I create the TreeView in the XAML and I do not see any way to do a Binding to the "SelectedItem" and "ItemSource" or any way to bring a query.
Tried this solution: Recursive XAML binding data templates on the Universal Windows Platform
and I made it work with a query, it works for me, but nevertheless I need to manage other fields and I would like to be able to handle the one in this example:
Windows Dev Centre: Tree View
I want this, but with Bindings to ViewModel in UWP:
回答1:
As the document you refered about TreeView, the Data binding to the ItemsSource property on TreeView and TreeViewItem is in Insider Preview build and SDK. You can follow the document Tree view using data binding part to achieve this function, but you should install the latest Windows 10 Insider Preview build and SDK, target you app on the insider preview build and test it in the insider preview build OS device.
来源:https://stackoverflow.com/questions/51850202/how-to-bind-a-treeview-in-uwp-to-a-viewmodel