问题在于,DataGrid中的空行没有出现,用户因此不能添加数据。
以下是代码:
System.Collections.ObjectModel.ObservableCollection<CoreVocabularyEntry> dataList = new System.Collections.ObjectModel.ObservableCollection<CoreVocabularyEntry>();
public VocabularyToolWindow()
{
InitializeComponent();
dataList.Add(new CoreVocabularyEntry { Foreign = "ja", Native = "ano" });
ListCollectionView view = new ListCollectionView(dataList);
WordsDataGrid.ItemsSource = dataList;
WordsDataGrid.CanUserAddRows = true;
MessageBox.Show(view.CanAddNew.ToString());
}
我无法理解为什么view.CanAddNew等于false。这看起来是一个非常标准的场景,所以我可能错过了一些显而易见的东西。有人能告诉我代码有什么问题吗?CoreVocabularyEntry只是以下内容:
public struct CoreVocabularyEntry : IVocabularyEntry
{
#region IVocabularyEntry Members
public string Foreign
{
get;
set;
}
public string Native
{
get;
set;
}
#endregion
}
Thx, J.K.