【问题标题】:Update ActiveDataItem of XamDataGrid on adding new record在添加新记录时更新 XamDataGrid 的 ActiveDataItem
【发布时间】:2012-08-22 17:17:32
【问题描述】:

我正在使用带有 MVVM 架构的 WPF,我面临的问题是当我将新记录添加到网格并按 Enter 时,该记录未设置为活动记录。 只有当我单击其他记录,然后再次单击新记录时,它才会更新。

<igDP:XamDataGrid  Name="xamDataGrid1" Width="700" Height="200" HorizontalAlignment="Center" ActiveDataItem="{Binding Listener,Mode=TwoWay}"  DataSource="{Binding GridData.Tables[0].DefaultView}" Padding="50">

有没有一种方法可以将新添加的记录设置为 activedataitem 属性,以便它可以调用视图模型中的侦听器? 我必须从视图模型中将新记录插入到数据库中。

【问题讨论】:

  • 你绑定什么类型的收藏?您可以在 ViewModel 中使用 CollectionChanged 事件来将项目添加到集合中吗?

标签: wpf mvvm infragistics xamdatagrid


【解决方案1】:

首先为DataSource创建一个集合并绑定它。接下来绑定ActiveDataItem。在集合中,添加新元素。之后,您可以将集合中的最后一个元素提供给 ActiveDataItem

【讨论】:

  • 这显然不是答案.... OP 显然已经有一个数据源集。问题是,当您添加一行时,绑定的 Active 数据项为空。
猜你喜欢
  • 1970-01-01
  • 2015-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多