Skip to content

Instantly share code, notes, and snippets.

@nickdarnell
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save nickdarnell/c4ec71d8794191d74fd6 to your computer and use it in GitHub Desktop.

Select an option

Save nickdarnell/c4ec71d8794191d74fd6 to your computer and use it in GitHub Desktop.
public static void CheckForBindingErrors(DependencyObject parent)
{
// Examine parent for binding errors
LocalValueEnumerator localValues = parent.GetLocalValueEnumerator();
while (localValues.MoveNext())
{
LocalValueEntry entry = localValues.Current;
if (BindingOperations.IsDataBound(parent, entry.Property))
{
BindingExpression binding =
BindingOperations.GetBindingExpression(parent, entry.Property);
if (binding.DataItem == null)
continue;
if (binding.Status == BindingStatus.PathError)
{
// Found binding error
}
}
}
// Examine children for binding errors
for (int i = 0; i != VisualTreeHelper.GetChildrenCount(parent); ++i)
{
DependencyObject child = VisualTreeHelper.GetChild(parent, i);
CheckForBindingErrors(child);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment