WPF DataGrid - 新条目的行不可见 [英] WPF DataGrid - row for new entry not visible

查看:154
本文介绍了WPF DataGrid - 新条目的行不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是DataGrid中的空白行没有出现,ergo用户无法添加数据。
这里是代码:

The problem is, that the blank row in the DataGrid isn't appearing, ergo user can not add data. Here is the code:

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只是以下内容:

I can't figure out why view.CanAddNew equals false. This looks like a pretty standart scenario, so there's probably something obvions I'm missing. Can someone tell me what is wrong with the code ? CoreVocabularyEntry is just the following:

public struct CoreVocabularyEntry : IVocabularyEntry
{
    #region IVocabularyEntry Members

    public string Foreign
    {
        get;
        set;
    }

    public string Native
    {
        get;
        set;
    }

    #endregion
}

Thx ,JK

推荐答案

移动 WordsDataGrid.CanUserAddRows = true; 您设置DataGrid的ItemSource。

Move WordsDataGrid.CanUserAddRows = true; above the statement where you set the DataGrid's ItemSource.

编辑:

只是注意到你没有不实施 IEditableObject 。您需要这样做才能使用DataGrid的编辑功能。

Just noticed you didn't implement IEditableObject. You'll need to do that for using the editing features of the DataGrid.

这篇关于WPF DataGrid - 新条目的行不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆