在我的程序中,我有TreeView
由ViewModel / Model实现和管理。
这是用于将每个节点添加到树的方法,它位于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
值。我该如何调用该值?例如,将textBox
的内容设置为等于其中一个DisplayNames
...
现在我已经达到了:
TextBox = Tree.SelectedItem.Children //This is where I am guessing that I need to use a method like .Count()
谢谢。
更新1
TreeView的XAML:
<TreeView ItemsSource="{Binding BlockingTree.BlockTree}" SelectedItemChanged="Tree_SelectedItemChanged" PreviewMouseRightButtonDown="Tree_PreviewMouseRightButtonDown" ... >
答案 0 :(得分:0)
试试这个:
<TreeView ItemsSource="{Binding BlockingTree.BlockTree}" DisplayMemberPath="DisplayName" SelectedItemChanged="Tree_SelectedItemChanged" PreviewMouseRightButtonDown="Tree_PreviewMouseRightButtonDown" x:Name="TreeViewBox" ... >
<TextBox Text="{Binding SelectedItem.DisplayName, ElementName=TreeViewBox}" />