如何创建在WPF DataGrid中的新行,当它绑定到XmlDataProvider? [英] How do I create a new row in WPF DataGrid when it is bound to an XmlDataProvider?

查看:465
本文介绍了如何创建在WPF DataGrid中的新行,当它绑定到XmlDataProvider?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有绑定到WPF DataGrid控件的XmlDataProvider项目。我有设置DataGrid中绑定如下:

I have a project with an XmlDataProvider bound to a WPF DataGrid control. I have the bindings on the DataGrid set up as follows:

<dg:DataGrid ItemsSource="{Binding Source={StaticResource XmlData}, XPath=Root/People/Person}"
             AutoGenerateColumns="False">
    <dg:DataGrid.Columns>
        <dg:DataGridTextColumn Header="ID" Binding="{Binding XPath=ID}"/>
        <dg:DataGridTextColumn Header="Name" Binding="{Binding XPath=Name}"/>
    </dg:DataGrid.Columns>
</dg:DataGrid>

用户可以使用DataGrid没有任何问题编辑条目。我不能设法做到的是让用户添加使用DataGrid一个新行(即一个新的Person)。我怎样才能让这个

Users can edit entries using the DataGrid without any problems. What I cannot manage to accomplish is allowing the user to add a new row (i.e. a new Person) using the DataGrid. How can I allow this?

推荐答案

请确保您设置:<?code> CanUserAddRows =真和绑定类的默认构造函数是可用的。

Make sure that you set: CanUserAddRows="True" and that the default constructor of a bound class is available.

这篇关于如何创建在WPF DataGrid中的新行,当它绑定到XmlDataProvider?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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