开发者

How can I check the calling command within RowEditEnding in WPF, to be sure I want to execute the event?

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)
{
开发者_Go百科    if ( CommandToDeleteRow || CommandToGoToForm )
        return;
    if (!allFieldsAreValid)
    {
        e.Cancel = true;
        return;
    }
    return;
}

Thanks!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜