简体   繁体   English

WPF datagrid允许用户添加行?

[英]WPF datagrid allow user to add rows?

I would like my WPF Datagrid that is bound to my observable collection to have the blank row at the bottom so that the user can add more info. 我希望绑定到我的可观察集合的WPF Datagrid在底部有一个空行,以便用户可以添加更多信息。 I've successfully bound the data, ie I can see it. 我已成功绑定数据,即我可以看到它。

Why is the 'new' blank row not showing? 为什么“新”空白行没有显示? Here is my xaml declaration: 这是我的xaml声明:

<UserControl.Resources>
  <CollectionViewSource x:Key="MyItems" Source="{Binding Path=AllItems}">
  </CollectionViewSource>
</UserControl.Resource>

<my:DataGrid HorizontalAlignment="Stretch"
  AutoGenerateColumns="True"
  SelectionUnit="FullRow"
  CanUserAddRows="True"
  CanUserDeleteRows="True"
  DataContext="{StaticResource MyItems}"
  ItemsSource="{Binding}">

PS: I'm using Josh Smith's MVVM implementation . PS:我正在使用Josh Smith的MVVM实现 I have also read some SO posts on the issue and they have not helped . 我也读过一些关于这个问题的SO 帖子 ,但他们没有帮助

Thanks in advance. 提前致谢。

Update 2010-01-14: 更新2010-01-14:

When the usercontrol load event occurs, "CanUserAdddRows" is false. 当usercontrol load事件发生时,“CanUserAdddRows”为false。 I suspect is has something to do with the conditions listed here . 我怀疑这与这里列出的条件有关。

Found the problem. 发现了问题。 My constructor in the object that's part of my ObservableCollection wasn't declared public. 我的ObservableCollection的对象中的构造函数未声明为public。

*Hits head* *击中头部*

Thanks for your time. 谢谢你的时间。

确保ObeservableCollection中的对象具有默认的无参数构造函数。

The new blank row will depend if the collection you are binding implements IEditableCollectionView. 新的空行将取决于您绑定的集合是否实现了IEditableCollectionView。 see here . 看到这里 That being said i have found that sometimes it works well and other times unexplainably it seems not to, but the IEditableCollectionView is a start 话虽如此,我发现有时它运行良好,其他时间似乎无法解释,但IEditableCollectionView是一个开始

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM