How to bind a treeview in UWP to a ViewModel?

≡放荡痞女 提交于 2021-01-28 09:35:43

问题


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: Example I want


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!