Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DataGrid默认为空行(并且始终为空)_C#_Wpf_Datagrid - Fatal编程技术网

C# DataGrid默认为空行(并且始终为空)

C# DataGrid默认为空行(并且始终为空),c#,wpf,datagrid,C#,Wpf,Datagrid,你好 我尝试在默认情况下使用空行创建DataGrid,如果用户删除所有行,DataGrid应该添加一个新的空行 我尝试这样做: <DataGrid AutoGenerateColumns="False" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Name="dg1" ItemsSource="{Bindin

你好

我尝试在默认情况下使用空行创建DataGrid,如果用户删除所有行,DataGrid应该添加一个新的空行

我尝试这样做:

<DataGrid AutoGenerateColumns="False" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2"
                              Name="dg1"     
                              ItemsSource="{Binding Path=RowColl}"   
                                  CanUserAddRows="True"
                                  CanUserDeleteRows="True"
                                  IsEnabled="True"
                                  IsReadOnly="False"
> ...</DataGrid>
。。。
在*.xaml.cs:

RowColl = new ObservableCollection<Row>();
dg1.ItemsSource = RowColl;
RowColl=新的ObservableCollection();
dg1.ItemsSource=RowColl;
但是没有空行

请告诉我如何在默认情况下获取空行,并始终将1行作为空行。 谢谢大家!

用这个

myDataGridView.AllowUserToAddRows = true;

它将在datagrid视图的末尾显示空行。

我找不到此字段请查看,我认为它正是您所需要的。