开发者

WPF databinding How to create a TreeView with a root and bind its children to a list?

开发者 https://www.devze.com 2023-02-06 19:46 出处:网络
For example if I have a List = {\"A\", \"B\", \"C\"}, I want the treeview to be +Root -A -B -C I tried <TreeView>

For example if I have a List = {"A", "B", "C"}, I want the treeview to be

+Root
 -A
 -B
 -C

I tried

    <TreeView>
        <TreeViewItem Header ="Root">开发者_运维百科;
            <TreeViewItem ItemsSource="{Binding Path=List}"/>
        </TreeViewItem>
    </TreeView>

but the result is

+Root
 -                      (just an empty node)
  -A
  -B
  -C

which is not what I want


Try this:

<TreeView>
    <TreeViewItem Header ="Root" ItemsSource="{Binding Path=List}"/>
</TreeView>
0

精彩评论

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