如何将 UWP 中的树视图绑定到 ViewModel?

How to bind a treeview in UWP to a ViewModel?

我目前在 UWP 工作,我需要创建一个 TreeView 来分层存储服务查询。例子: Example I have

我把信息保存在一个 public ObservableCollection <Model> name_of_object {get; set; } = new ObservableCollection <Model> ();

但是我在 XAML 中创建了 TreeView,但我没有看到任何方法可以对 "SelectedItem" 和 "ItemSource" 进行绑定,也没有任何方法可以进行查询。

试过这个解决方案:

我让它与查询一起工作,它对我有用,但是我仍然需要管理其他字段,我希望能够处理这个例子中的那个:

Windows Dev Centre: Tree View

我想要这个,但是在 UWP 中绑定到 ViewModel:

正如您提到的关于 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 的文档,将您的应用定位到内部预览版本并在内部预览版本 OS 设备中对其进行测试。