我是一名有用的助手,可以为您进行文本翻译。以下是需要翻译的内容:
为了更新我使用的表格,我尝试了以下方法:
新项目似乎能够正确添加,但在listView上没有更新任何内容。
我已经阅读了像这样的教程:http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-1 我尝试添加其他帖子中建议的所有通知代码,但都不起作用。
希望能提供一些想法。
我在数据绑定方面遇到了巨大的问题。我已经阅读了这里的大多数帖子,这些帖子都是来自于遇到类似问题的人,但不知道为什么我就是无法理解。
我的表格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>
在我的代码中有:
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()
});
新项目似乎能够正确添加,但在listView上没有更新任何内容。
我已经阅读了像这样的教程:http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-1 我尝试添加其他帖子中建议的所有通知代码,但都不起作用。
希望能提供一些想法。
DataContext
? - nemesv