How can I check wpf bindings go to real properties?

I would like a simple way to ensure that all the bindings I declared in my xaml files go to real properties. Even better, I would like to instantiate my wpf window in unit test and call the method to make sure the bindings are correct.

Unfortunately, wpf does not even throw an exception if I have something wrong. This leaves me with the burden of "detecting" problems during the QA phase.

Does anyone know how I can better check my bindings?

+5
source share
2 answers

A suboptimal way would be to search the visual tree for all the dependency properties, and then check:

var bindingExpression = BindingOperations.GetBindingExpressionBase(dependencyObject, dependencyProperty);

if (bindingExpression != null)
{
    var status = bindingExpression.Status;
}

status - Unattached, .

, , .

+4

Visual Studio. , , TextBlock Title , "Title" "Ritle". :

System.Windows.Data: 39: BindingExpression: Ritle 'object' '' MessageWindow '(Name=' Window ')'. BindingExpression: Path = Ritle; DataItem = 'MessageWindow' (Name= 'Window'); "TextBlock" (Name= "WindowTitle" ); target "Text" ( "String" )

. Bea Stollnitz .

+1

All Articles