• behance
  • gitHub
  • google
  • linkedin
  • twitter
Debugging XAML

Debugging XAML

This is a really tough one sometimes. I’ve recently had to debug an error that initially seemed a bit odd. Viewing the main window XAML in Visual Studio 2008 or C# Express just gave me the dreaded “Object not set to an instance of an object.” error. Even though Blend rendered the screen without showing any problems. That in itself is not that odd since the two XAML editors operate very differently it seems.

After trying various things to find the bug I eventually opted for removing sections of XAML from the main screen until I ended up with a screen that would render exception free in the C# Express XAML pane. It turned out that the problem was with the style that was being applied to my TreeViewItems. I then set about looking at the XAML Dictionary that I had created in order to provide the custom styling for the Tree View. I couldn’t see any issues with it so I went back up the visual tree to the code in the main window XAML that applied the style. Turns out that I had the style referenced wrong. In stead of using DynamicResource I needed to be using StaticResource. Basically there was no real problem with either the window code or the style code, just the way it was being applied at design time.

Leave a reply

*