Although I love Xaml and the declarative person it makes me want to be, I feel even more strongly about fearless refactoring. If I fear renaming properties or moving types around, I do not refactor. And if I do not refactor regularly, my code begins to smell bad, which is a sure way to get my project featured the one place I do not want it 
So, I want to refactor, but Xaml makes me reluctant to do so. We do not set bindings in code behind, but we declare them (which I think is 'good') in Xaml. Visual Studio doesn't search Xaml files for binding-paths. And so I'm left in the dark about what impact my refactoring will have. Furthermore, binding-errors do not throw exceptions, but fail gracefully, leaving a naive unittest none the wiser.
I've tried to catch the RoutedEvent 'Binding.Error' on a higher level, but it doesn't propagate.
Nor does the LoadedEvent of controls, if the control does not explicitly call some Loaded eventhandler. In this approach I thought I would be able to catch the loaded event of the control while they are being put on the screen and register their binding to be checked later. If all your controls in question do declare a Loaded handler, then you could use something like this:
EventManager.RegisterClassHandler(typeof(Control), Control.LoadedEvent,
(RoutedEventHandler)delegate(object sender, RoutedEventArgs e)
{
// do your thing, throw an exception to let the unit test fail perhaps!
}, true );
But, like I said, this class handler will only fire if the control is already going to another Loaded event prior to this. Bummer.
Another approach would be to write a visual tree walker and question all the bindings in the screen about their status (a property of BindingExpression). This could be some trouble, but should be very do-able.
I've opted for yet another approach. I was using trusty Reflector to see how bindings work and discovered that binding errors are always shown in the output window. After some searching, it seems that even if you do not have any trace sources declared in your app.config, the visual studio debugger always switches the System.Windows.Data trace to the 'Warning'-level. And the warning level will trace a databinding error of code 35 if a binding is in error!
Well, quite an obvious solution then is to create your own trace-listener class and registering it in the app.config. To get it to work, your unit test will have to do a refresh of the Tracesources to get the traces to work: PresentationTraceSources.Refresh();
The Tracelistener:
public class UnitTestTracer : TraceListener
{
public override void Write(string message)
{
// throw your exception to make trace fail!
}
public override void WriteLine(string message)
{
// throw your exception to make trace fail!
}
}
And the app.config:
<system.diagnostics>
<sources>
<source name="System.Windows.Data" switchValue="Warning" >
<listeners>
<add name="unitTestListener" type="UnittestTestWPF.UnitTestTracer, UnittestTestWPF" />
</listeners>
</source>
</sources>
</system.diagnostics>
Simple, yet effective. The more I think about it, the more I like the approach!