WPF DataGrid - 新条目的行不可见

Jan*_*vil 3 c# wpf datagrid

问题是,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());
    }
Run Code Online (Sandbox Code Playgroud)

我不明白为什么 view.CanAddNew 等于 false。这看起来像是一个非常标准的场景,所以可能有一些我遗漏的东西。有人可以告诉我代码有什么问题吗?CoreVocabularyEntry 如下:

public struct CoreVocabularyEntry : IVocabularyEntry
{
    #region IVocabularyEntry Members

    public string Foreign
    {
        get;
        set;
    }

    public string Native
    {
        get;
        set;
    }

    #endregion
}
Run Code Online (Sandbox Code Playgroud)

谢谢,JK

小智 7

这可能比上面更简单。当我没有默认构造函数时,我遇到了这个问题,因此数据网格不知道如何添加新行。我唯一的构造函数需要提供大量信息。转到 List<> 的对象并添加一个构造函数,例如: public MyClass(){} 希望这会有所帮助!