如何检查 WPF 中 RowEditEnding 中的调用命令,以确保我想要执行该事件?
我有一些验证要求要在 RowEditEnding 事件处理程序中运行。但是,在某些情况下,这些命令不会运行:如果按下删除按钮,如果用户转到详细表单来处理记录等。
我如何检查调用命令以查看“在我尝试验证行中的数据之前,“规则的例外”正在发挥作用?
目前,伪代码看起来像这样:
private void resultsGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
if (!allFieldsAreValid)
{
e.Cancel = true;
return;
}
return;
}
我希望它看起来像这样:
private void resultsGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
if ( CommandToDeleteRow || CommandToGoToForm )
return;
if (!allFieldsAreValid)
{
e.Cancel = true;
return;
}
return;
}
谢谢!
I have some validation requirements to run within my RowEditEnding event handler. However, there are certain conditions under which those do not run: if the delete button is pressed, if the user goes to a detail form to work with the record, etc.
How can I check the calling command to see if one of the "Exceptions to the rule" is in play before I try to validate the data in the row?
Currently, the pseudo-code looks something like this:
private void resultsGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
if (!allFieldsAreValid)
{
e.Cancel = true;
return;
}
return;
}
I would like it to look like this:
private void resultsGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
if ( CommandToDeleteRow || CommandToGoToForm )
return;
if (!allFieldsAreValid)
{
e.Cancel = true;
return;
}
return;
}
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看一下在 DataGrid 中实现验证;这将允许您在模型中的单元格级别和行级别发生更改时执行验证。除此之外,您还可以查看 IEditableObject 作为它将允许您在模型中实施回滚更改。
这将使您不再使用事件处理程序,而更多地转向 MVVM 方法;在克服最初的障碍之后,这将使您的生活变得更轻松。
Take a look at implementing validation within the DataGrid; which will allow you to perform the validation whenever an item changes within your model at both the cell and row level. On top of that you can also check out IEditableObject as it will allow you to implement rolling back changes within your model.
This will move you away from making use of event handlers as well and more towards an MVVM approach; which will after the initial hurdle make your life easier.