Debugging WPF Bindings

      No Comments on Debugging WPF Bindings

WPF + MVVM is very common way to make windows apps. It introduces concept of data binding. We create a view-model based on one or many models and bind it to the view. Usually it is easy….
But how do you debug bindings if something is not going right? For example you have Control Templates and styles and so on introduced in your app.

Since WPF 3.5 there is new diagnostics featured that you can turn on and it will output detailed binding messages to the Output window. Immensely helpful when you are trying to figure out why your binding does not work or works incorrectly.

To set it up first add diagnostics to your namespace:

<Window x:Class=”Tester.Window2″ 

Then enable it on per-binding instance as such:

ItemsSource=”{Binding Path=PaneItems, 

Now when you run your app watch Output window for clues on why binding is failing.

Hope this helps save your sanity while debugging bindings as much as it does mine 🙂

Follow me:

Leave a Reply

Your email address will not be published. Required fields are marked *