问题描述
我有麻烦让我的数据,以正确绑定的巨大数额。我从人的类似问题在这里阅读上的大部分职位,但由于某种原因,我不能得到它的点击。
I am having an immense amount of trouble getting my data to bind correctly. I have read most the posts on here from people with similar issues, but for some reason I just can't get it to click.
我的表中的XML是:
<Window ... DataContext="{Binding RelativeSource={RelativeSource Self}}" >
...
<ListView Height="124" HorizontalAlignment="Left" Margin="12,46,0,0" Name="listViewDocuments" VerticalAlignment="Top" Width="Auto" DataContext="{Binding DocumentList}">
<ListView.View>
<GridView>
<GridViewColumn Width="160" Header="Description" DisplayMemberBinding="{Binding Description}"/>
<GridViewColumn Width="160" Header="Date Filed" DisplayMemberBinding="{Binding DateFiled}"/>
<GridViewColumn Width="160" Header="Filed By" DisplayMemberBinding="{Binding UserFiledName}"/>
<GridViewColumn Width="150" Header="Page" DisplayMemberBinding="{Binding Pages}"/>
<GridViewColumn Width="150" Header="Notes" DisplayMemberBinding="{Binding Notes}"/>
<GridViewColumn Width="Auto" Header="" />
</GridView>
</ListView.View>
</ListView>
在我的code我有:
Within my code I have:
public ObservableCollection<Document> _DocumentList = new ObservableCollection<Document>();
...
public ObservableCollection<Document> DocumentList{ get { return _DocumentList; } }
...
public class Document
{
public string Description { get; set; }
public string DateFiled { get; set; }
public string UserFiledName { get; set; }
public string Pages { get; set; }
public string Notes { get; set; }
public string Tag { get; set; }
}
在试图更新我使用表
_DocumentList.Add(new Document
{
Description = dr["Description"].ToString(),
DateFiled = dr.GetDateTime(dr.GetOrdinal("DateFiled")).ToShortDateString(),
UserFiledName = dr["UserFiledName"].ToString(),
Pages = dr.GetInt32(dr.GetOrdinal("Pages")).ToString(),
Notes = dr["Notes"].ToString(),
Tag = dr["FileID"].ToString()
});
新项目似乎越来越正确添加,但没有更新的列表视图。
New items seem to be getting added correctly, but nothing is updated on the listView.
我已经经历教程是这样写着:的
I have read through tutorials like this: http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-1
我试图将所有的通知code,它建议在其他职位。没有什么工作对我来说。
And I have tried adding all of the notification code that is suggested in other posts. Nothing is working for me.
和想法将AP preciated。
And ideas would be appreciated.
推荐答案
而不是的DataContext ={结合DocumentList}
尝试的ItemsSource = {结合DocumentList}
。
这篇关于绑定一个ObservableCollection到ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!