How to bind WPF TreeView to a List programmatically?

后端 未结 2 740
灰色年华
灰色年华 2021-01-07 08:16

So I am very new to WPF and trying to bind or assign a list of Drink values to a wpf treeview, but don\'t know how to do that, and find it really hard to find anything onlin

2条回答
  •  执笔经年
    2021-01-07 08:21

    You can just set:

    treeView1.ItemsSource = coldDrinks;
    

    However, I question the use of a TreeView here. You're obviously showing flat, non-hierarchical data, so there is no reason to use a TreeView.

    Why not just use a ListView or ListBox?

提交回复
热议问题