how to insert a child item in a treeview C# WPF

后端 未结 3 750
小蘑菇
小蘑菇 2020-12-22 00:43

I want to add a child item in a TreeViewItem that was added previously. The problem with code like this:

How to insert a child node in a TreeView Control in WPF?

3条回答
  •  心在旅途
    2020-12-22 01:11

    Maybe you forgot the tags? If you have the following in your xaml file:

        
            Hello
            World
        
    

    And the following in the code-behind:

    var a = MyTreeView.Items.GetItemAt(0) as string;
    var b = MyTreeView.Items.GetItemAt(0) as TreeViewItem;
    var c = MyTreeView.Items.GetItemAt(1) as string;
    var d = MyTreeView.Items.GetItemAt(1) as TreeViewItem;
    

    Variables a and d will be null whereas b will be a TreeViewItem and c will be a string.

提交回复
热议问题