Welcome to MSDN Blogs Sign in | Join | Help

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!

Published Tuesday, July 29, 2008 5:20 AM by Michael S. Scherotter
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Pregnant Man » Uri property in a Silverlight 2 UserControl

# Silverlight Cream for July 30, 2008 -- #338

Mark Monster on cross-comain-scripting issues, Page Brooks on his treadmill, Mike Snow on the Mouse Wheel

Wednesday, July 30, 2008 12:17 PM by Community Blogs

# re: Uri property in a Silverlight 2 UserControl

That's resolved my problem too. Thanks.

Thursday, July 31, 2008 7:35 PM by shinyzhu

# re: Uri property in a Silverlight 2 UserControl

Thanks for the advice! I just used a string so far.

Monday, August 04, 2008 4:25 AM by Anna

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker