如何以编程方式从c#中使用xmlDataProvider进行databindet的wpf树视图中选择rootnode? p>
在我的情况下,Rootnode来自DataType =“cards”:
<cards>
<category />
<card />
<card />
<card />
</cards>
我试过了:
//AddNode
xmlDataProvider.Document.DocumentElement["cards"].AppendChild(newNode);
//Select rootnode
treeView.SelectedValuePath = "cards";
//the hard way:
//treeView.SelectedValuePath = ((XmlNode)treeView.Items.GetItemAt(0)).Name.LocalName";
treeView.Focus();
但未选择Rootnode: - (
答案 0 :(得分:6)
我做到了: - )
var treeViewItem = treeView.ItemContainerGenerator.ContainerFromIndex(0) as TreeViewItem;
treeViewItem.Focus();
答案 1 :(得分:0)
(treeView.Items [0] as TreeViewItem).Focus();我认为应该有用。