Tuesday, January 14, 2014

Silverlight Image Converter

I wrote a simple converter to go from an enumerated type to a different image per value.  Sounds simple, right?  It checks the value, then returns a new BitmapImage with the appropriate image path:

if( v == Enum.Thing ) path = "/images/thing.png";
return new BitmapImage(new Uri(path, UriKind.Relative));

Unfortunately no image appeared.  So frustrating!  It turned out that even though I was starting with a leading slash, it was loading from the wrong root.  No errors, just no image.  A quick run-through with Fiddler showed me what was going on.  After examining the code, I was sure everything was right.  Fiddler is the best tool for finding those weird things that come from needing that closer look!

No comments:

Post a Comment