防止datagrid中的行更改

编程入门 行业动态 更新时间:2024-10-27 17:17:59
本文介绍了防止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中的行更改

本文发布于:2023-11-11 10:11:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1578132.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:datagrid

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!