如何检查 WPF 中 RowEditEnding 中的调用命令,以确保我想要执行该事件?

发布于 2024-10-07 12:40:22 字数 680 浏览 0 评论 0原文

我有一些验证要求要在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只是我以为 2024-10-14 12:40:22

看一下在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文