如何向DataGrid添加空行?

我需要允许用户添加直接在DataGrid中的信息,但是“CanUserAddRows”属性不起作用,只显示如下:

在此处输入图像描述

这是我的DataGrid:

         

编辑

这是新的网格代码:

          

这是我的代码背后:我的ObservableCollection:

 public ObservableCollection lstPerson { get; set; } 

我的主窗口

 public MainWindow() { InitializeComponent(); DataContext = this; lstPerson = new ObservableCollection(); } 

我的人类

 public class Person { public int No { get; set; } public string Name { get; set; } public string Carrer { get; set; } public string Group { get; set; } public int Age { get; set; } } 

1)改变网格xaml

           

2)在ViewModel或CodeBehind中定义您的集合

 public ObservableCollection GridCollection { get; set; } 

3)使用前初始化收集

 public MainWindow() { InitializeComponent(); DataContext = this; GridCollection = new ObservableCollection(); } 

4)毕竟你会得到这个,你可以通过GUI在网格中添加项目,它们将存储在集合中 结果

您必须定义ItemsSource。

在你的代码背后:

 List list = new List(); dtgPersons.ItemsSource = list;