Uri property in a Silverlight 2 UserControl

In creating a Silverlight 2 UserControl, I had a need to include a Uri parameter, so I added a property. 

 class MyControl : UserControl
{
    ...
    public Uri Source {get;set;}
    ...
}

That compiled and ran just fine but when I tried to set the value via XAML, I got an AG_E_PARSER_BAD_PROPERTY_VALUE error. The property was missing a type converter, a class that converts between a string and the property value. I added a using directive and the attribute to the property specifying to use the built-in UriTypeConverter:

 using System.ComponentModel;
 class MyControl : UserControl
{
    ...
    [TypeConverter(typeof(UriTypeConverter))]
    public Uri Source {get;set;}
    ...
}

That fixed it!

Comments

  • Anonymous
    July 29, 2008
    PingBack from http://wordnew.acne-reveiw.info/?p=14013

  • Anonymous
    July 30, 2008
    Mark Monster on cross-comain-scripting issues, Page Brooks on his treadmill, Mike Snow on the Mouse Wheel

  • Anonymous
    July 31, 2008
    That's resolved my problem too. Thanks.

  • Anonymous
    August 03, 2008
    Thanks for the advice! I just used a string so far.