MVVM 环境中的 WPF Datagrid RowEditEnding
我一直在尝试使用以下方法捕获用户输入数据网格的值
<b:Interaction.Triggers>
<b:EventTrigger EventName="RowEditEnding">
<b:InvokeCommandAction Command="{Binding ReleaseRowEditEndingCommand}" CommandParameter="{Binding SelectedRelease}"/>
</b:EventTrigger>
但这不起作用,我现在在阅读 this 后明白了这一点StackOverflow 上的文章。所提出的解决方案似乎都是基于直接调用与引发的事件相匹配的方法签名,在这种情况下,
private void OnRowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
是否有人在 MVVM 情况下完成了在 rowedit 后获取值?所有解决方案似乎都将事件紧密绑定到 XAML,如果可能的话,我想避免这种情况。
I've been trying to capture the values that a user enters into a datagrid by using
<b:Interaction.Triggers>
<b:EventTrigger EventName="RowEditEnding">
<b:InvokeCommandAction Command="{Binding ReleaseRowEditEndingCommand}" CommandParameter="{Binding SelectedRelease}"/>
</b:EventTrigger>
But this doesn't work and I now understand this afte reading this article on StackOverflow. The solutions presented all seem to be based on directly calling a method signature that matches the event being raised, in this case
private void OnRowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
Has anyone accomplished getting the values post-rowedit in an MVVM situation? All the solutions seem to tightly bind the event to the XAML and I'd like to avoid that, if possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案实际上比我想象的要容易。我更改了 XAML,现在可以获取视图模型上 RowEditEnding 事件中的值。这是数据网格上数据列的之前:
之后
The solution was actually easier than I thought. I changed the XAML and I can now get the values in the RowEditEnding event on the View Model. Here's the before on the data columns on the datagrid:
After
您可以尝试将数据包装在 ListCollectionView 中并将 DataGrid 绑定到 ListCollectionView。然后,在 ViewModel 中,挂钩 ListCollectionView.CurrentChanging 事件以在移动到新行之前处理更改。
You could try wrapping your data in a ListCollectionView and binding the DataGrid to the ListCollectionView. Then, in your ViewModel, hook into the ListCollectionView.CurrentChanging event to process your changes before moving to the new row.