我已经研究了这一点,并且很遗憾:我有一个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中的行更改
发布评论