1<datagrid x:name="DataGrid"Horizontalalignment=" Left"margin="10,10,0,0"Verticalalignment="Top"Width="620"height="269"autogeneratecolumns="False"gridlinesvisibility="None"Canuserdeleterows="False"2Canuseraddrows="False"Itemssource="{Binding Liststudent}">3<datagridtextcolumn header="numbering"Width=" the"binding="{Binding Student.studentid}"/>4<datagridtextcolumn header="name"Width=" the"binding="{Binding Student.name}"/>5<datagridtextcolumn header="Age"Width=" the"binding="{Binding Student.age}"/>6<datagridtextcolumn header="Sex"Width=" the"binding="{Binding Student.sex}"/>7<datagridtextcolumn header="features"Width=" -"binding="{Binding Student.remark}"/>8<datagridtemplatecolumn header="selected"Sortmemberpath="IsSelected"Width=" -">9<DataGridTemplateColumn.CellTemplate>Ten<DataTemplate> One<checkbox ischecked="{Binding path=isselected,updatesourcetrigger=propertychanged}"Verticalalignment="Center"Horizontalalignment="Center"Command="{Binding Path=datacontext.selectstudentitemcommand,relativesource={relativesource mode=findancestor, Ancestortype={x:type DataGrid} }}" A/> -</DataTemplate> -</DataGridTemplateColumn.CellTemplate> the</DataGridTemplateColumn> -</DataGrid>
Error "Item collection must be empty before using ItemsSource"
You can see that the columns are not displayed correctly in the designer because fewer datagrid.columns nodes
1<datagrid x:name="DataGrid"Horizontalalignment=" Left"margin="10,10,0,0"Verticalalignment="Top"Width="620"height="269"autogeneratecolumns="False"gridlinesvisibility="None"Canuserdeleterows="False"2Canuseraddrows="False"Itemssource="{Binding Liststudent}">3<DataGrid.Columns>4<datagridtextcolumn header="numbering"Width=" the"binding="{Binding Student.studentid}"/>5<datagridtextcolumn header="name"Width=" the"binding="{Binding Student.name}"/>6<datagridtextcolumn header="Age"Width=" the"binding="{Binding Student.age}"/>7<datagridtextcolumn header="Sex"Width=" the"binding="{Binding Student.sex}"/>8<datagridtextcolumn header="features"Width=" -"binding="{Binding Student.remark}"/>9<datagridtemplatecolumn header="selected"Sortmemberpath="IsSelected"Width=" -">Ten<DataGridTemplateColumn.CellTemplate> One<DataTemplate> A<checkbox ischecked="{Binding path=isselected,updatesourcetrigger=propertychanged}"Verticalalignment="Center"Horizontalalignment="Center"Command="{Binding Path=datacontext.selectstudentitemcommand,relativesource={relativesource mode=findancestor, Ancestortype={x:type DataGrid} }}" -/> -</DataTemplate> the</DataGridTemplateColumn.CellTemplate> -</DataGridTemplateColumn> -</DataGrid.Columns> -</DataGrid>
Change to the above can
The item collection must be empty before WPF exception is used with ItemsSource