开发者

Select Rootnode from a WPF-TreeView

How to programmatically select the rootnode from a wpf treeview in c# that is databinde开发者_开发技巧t with a xmlDataProvider?

In my case the Rootnode is from DataType="cards":

<cards>
    <category />
    <card />
    <card />
    <card />
</cards>

I tried this:

//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();

but the Rootnode isn´t selected :-(


I made it :-)

var treeViewItem = treeView.ItemContainerGenerator.ContainerFromIndex(0) as TreeViewItem;

treeViewItem.Focus();


(treeView.Items[0] as TreeViewItem).Focus(); should work, i think.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜