Add SubItems to ListView without using XAML

后端 未结 3 1096
自闭症患者
自闭症患者 2021-01-03 06:30

How do you add sub-items to a ListView? I need to generate everything dynamically, but every example I\'ve found uses XAML.

Non-WPF was so simple:

3条回答
  •  耶瑟儿~
    2021-01-03 06:58

    The "WPF way" would be to bind your listview to a collection that represents the data you want to display. Then add objects containing data to that collection. You almost never should have to deal with adding ListViewItems to your list manually as you are planning to do. I could come up with an example but there's many threads here on SO already that solve exactly this problem:

    1. Add programmatically ListViewItem to Listview in WPF
    2. WPF ListView - how to add items programmatically?

提交回复
热议问题