WPF ListView的 - 如何添加项目编程? [英] WPF ListView - how to add items programmatically?
本文介绍了WPF ListView的 - 如何添加项目编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
即使我知道这并不理想 - 我需要以编程方式填充一个ListView(无论何种原因)
Even if I know it's not ideal - I need to programmatically populate a listView (for whatever reason).
我声明我列的标记:
<ListView.View>
<GridView>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}"/>
<GridViewColumn Header="Value" DisplayMemberBinding="{Binding Path=Value}"/>
</GridView>
</ListView.View>
我添加在code这样的项目(这显然是在一个循环中):
I am adding the items like this in code (it's obviously in a loop):
MyData data = getDataItem(index); //< -- whatever
ListViewItem item = new ListViewItem();
item.DataContext = data;
this.myListView.Items.Add(item);
其中迈德特定义为:
Where MyData is defined as:
public class MyData
{
public string Name { get; set; }
public string Value { get; set; }
}
被添加的项目(我可以看到行),但我没有看到任何内容。
The items are being added (I can see the rows) but I don't see any content.
任何人任何线索?
任何帮助AP preciated!
Any help appreciated!
推荐答案
它的工作原理改变code为:
It works changing the code to:
MyData data = getDataItem(index); //< -- whatever
this.myListView.Items.Add(data);
现在看起来很明显,但...去数字!
Now it looks obvious but ... go figure!
这篇关于WPF ListView的 - 如何添加项目编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文