经过一整天的工作后不确定是我……或者 WPF 类型的树有什么不同。我正在向树中添加数据,然后当它是父节点时需要添加其子节点,但 SelectedItem 始终为空!
任何评论或指示都会有所帮助。
谢谢。
XAML:
<TreeView x:Name="TreeView1" Grid.Row="0">
</TreeView>
Code:
TreeView myTree = FindChild<TreeView>(Application.Current.MainWindow, "TreeView1");
myTree.Items.Add(ObjEmployee.Tag);
TreeViewItem tvi = (TreeViewItem) myTree.SelectedItem;
//my assumption was that when an item is added to tree most recent used node will be selected but it seems something is avoiding it or maybe works in a different way.