防止datagrid中的行更改 [英] preventing row change in datagrid

查看:134
本文介绍了防止datagrid中的行更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经研究了这一点,并且很遗憾:我有一个WPF DataGrid,并使用MVVM模型。在某些情况下,我想要防止在DataGrid中更改一行的能力。我已经研究了这一点,并尝试过如下技术:这里

I have researched this and am stumped: I have a WPF DataGrid, and using an MVVM model. I want to, under certain circumstances, prevent the ability to change a row in the DataGrid. I have researched this and have tried techniques like the one found here.

在实践中,这是有效的,但是有一个不希望的闪烁(它选择点击的行一会儿然后回去以前的选择),虽然这是一个接近的解决方案,我希望有一个更优雅的方式,如防止行变化在第一位。

In practice, this works, however there is an undesirable 'flicker' (it selects the clicked row for a moment then goes back to the previous selection), while this is a close solution I wish there was a more elegant way such as preventing the row change at all in the first place.

我很惊讶,没有一个SelectionChanging或BeforeSelectionChanged,所以我可以取消事件的触发;强制阻止我的观点模式的指数变化似乎没有任何区别。

I am surprised there is not a SelectionChanging or BeforeSelectionChanged so I could cancel the event from firing; and forcibly preventing the index change in my view model does not seem to make any difference.

我该怎么做?

谢谢。

推荐答案

如果您采用 previewkeydown previewmousedown 事件,只需在特定情况下调用 e.Handled = true

what happens if you take the previewkeydown and previewmousedown events and just call e.Handled=true under your certain circumstance?

编辑:
以满足mvvm风格:
您可以创建一个行为 DependencyProperty 你可以绑定你的情况。
在这种行为你可以处理的事件,也许一些其他的东西,就像用户点击一个数据行或头...

to satisfy the mvvm style: you can create a Behavior with a DependencyProperty you can bind your circumstance to. in this behavior you can handle the events and maybe some other stuff, like does the user click on a datarow or header...

这篇关于防止datagrid中的行更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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