WPF datagrid允许用户添加行? [英] WPF datagrid allow user to add rows?

查看:211
本文介绍了WPF datagrid允许用户添加行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的WPF Datagrid绑定到我的observable集合的空白行在底部,以便用户可以添加更多的信息。我已成功绑定数据,即我可以看到它。



为什么新空白行不显示?这是我的xaml声明:

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

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

PS:我正在使用 Josh Smith的MVVM实现。我也在这个问题上阅读了一些SO 帖子他们没有帮助



提前感谢



更新2010-01-14:



当用户控制加载事件发生时,CanUserAdddRows为false。我怀疑这与列出的条件有关[a href =http://blogs.msdn.com/vinsibal/archive/2008/10/01/overview-of-the-editing-features-in-the- wpf-datagrid.aspxrel =noreferrer>这里。

解决方案

发现问题。我的ObservableCollection中的对象中的构造函数未被声明为public。



*点击头*



谢谢你的时间。


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. I've successfully bound the data, i.e. I can see it.

Why is the 'new' blank row not showing? Here is my xaml declaration:

<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. I have also read some SO posts on the issue and they have not helped.

Thanks in advance.

Update 2010-01-14:

When the usercontrol load event occurs, "CanUserAdddRows" is 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.

*Hits head*

Thanks for your time.

这篇关于WPF datagrid允许用户添加行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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