1

I may have worded the title wrongly here. But what I have is the following user control class:

 public class CustomControl : UserControlBase
 {
       public String MyString { get; set; }
 }

When I include an instance of this user control on my page, I can quite easily change the value of MyString in the markup like:

<XYZ:CustomControl runat="server" MyString="A value" />

However, I want to include a property that is of type MyClass, and assign values to the 'child' class:

 public class CustomControl : UserControlBase
 {
       public String MyString { get; set; }
       public MyClass MyClass { get; set; }
 }

 public class MyClass
 {
       public String AString { get; set; }
 }

<XYZ:CustomControl runat="server" MyString="A value" MyClass.AString="Some value" />

Obviously the above won't work, but it gives you an idea of what I'm trying to achieve.

1 Answers1

-1

In a WPF application I would do something like this:

public class CustomControl : UserControlBase
{
       public String MyString { get; set; }
       public String AString { get; set; }

       [Description("Some description"), Category("Data")]
       public MyClass MyClass { get; set; }

}

You will be able to access the attribute in the XAML. The issue now is that your class must be able able to be converted from string to MyClass.

  • This post explains how to convert to class from a string: http://stackoverflow.com/questions/4876683/c-sharp-convert-dynamic-string-to-existing-class – Chris - Haddox Technologies Nov 14 '13 at 16:56
  • Would the user who down voted like to explain why? I am here to help if there is anything not working for you. – Chris - Haddox Technologies Nov 14 '13 at 18:49
  • I was not the one who down voted but my guess is that it was because the original question is about asp.net and not WPF. – Lost_Cause Nov 14 '13 at 19:10
  • Same Chris, not sure why there's a downvote on both of our answers. Especially since mine is the solution and no alternative was provided in the comments!? –  Nov 15 '13 at 08:23