在我的程序中,我有一个TreeView
由 ViewModel/Model 实现和管理的。
这是用于将每个节点添加到 Tree 的方法,它位于TreeView
ViewModel 中:
private TreeModel createNewNode(string value1, string value2, string value3 )
{
return new BlockingTreeModel()
{
DisplayName = "Example Node",
Children =
{
new TreeModel() { DisplayName = "Child 1: " + value1},
new TreeModel() { DisplayName = "Child 2: " + value2 },
new TreeModel() { DisplayName = "Child 3: " + value3 }
}
};
}
我想DisplayName
使用SelectedItem
. 我将如何调用该值?例如,将 a 的内容设置为textBox
孩子的DisplayNames
...
现在我已经做到了:
TextBox = Tree.SelectedItem.Children //This is where I am guessing that I need to use a method like .Count()
谢谢你。
更新 1
树视图的 XAML:
<TreeView ItemsSource="{Binding BlockingTree.BlockTree}" SelectedItemChanged="Tree_SelectedItemChanged" PreviewMouseRightButtonDown="Tree_PreviewMouseRightButtonDown" ... >