How to debug WPF bindings?

When playing with WPF and databindings i was a little frustrated with the lack of debug possibility’s of databindings in XAML. The problem is of course that XAML is no code.

The blog of Beatriz Costa offers some great solutions:
http://www.beacosta.com/blog/?p=52

The best is using the Converter solution, add the following class to your codebehind:
public class DebuggingConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                return value; // Add the breakpoint here!!
            }

            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                throw new NotImplementedException(“This method should never be called”);
            }
        }

In the XAML add a reference:
 xmlns:local=”clr-namespace:YOURNAMESPACE”
Then add the class as local resource
   
      
   
 
Then at last add the converter to the databinding:
 
And start debugging your databinding !

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.