WPF DataGrid Validation.HasError is always false (MVVM)

无人久伴 提交于 2019-12-03 17:20:01
M C

Ok i finally worked it out! The following Method from here does indeed work, but only after the Window containing my Datagrid is fully loaded (eg. in the Window / Usercontrol Loaded EventHandler):

public bool IsValid(DependencyObject parent)
{
    if (Validation.GetHasError(parent))
        return false;

    // Validate all the bindings on the children
    for (int i = 0; i != VisualTreeHelper.GetChildrenCount(parent); ++i)
    {
        DependencyObject child = VisualTreeHelper.GetChild(parent, i);
        if (!IsValid(child)) { return false; }
    }

    return true;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!