Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 992227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:13:56+00:00 2026-05-16T06:13:56+00:00

I have added the dependency property MyList to a wpf textbox. The dependency property

  • 0

I have added the dependency property MyList to a wpf textbox. The dependency property is of type List<string>. In order to make things easier in xaml I have defined a converter so that I can have following syntax:

<Grid>
    <controls:MyTextBox x:Name="Hello" MyList="One,Two" Text="Hello" />
</Grid>

In Visual Studio I can’t edit the property at all and in Expression Blend I can type in the string but it generates the following xaml:

<controls:MyTextBox x:Name="Hello" Text="Hello" >
 <controls:MyTextBox.MyList>
  <System_Collections_Generic:List`1 Capacity="2">
   <System:String>One</System:String>
   <System:String>Two</System:String>
  </System_Collections_Generic:List`1>
 </controls:MyTextBox.MyList>
</controls:MyTextBox>

Any ideas how I can just edit this property as a string in both Visual Studio and Blend??

public class MyTextBox : TextBox
{
    [TypeConverter(typeof(MyConverter))]
    public List<string> MyList
    {
        get { return (List<string>)GetValue(MyListProperty); }
        set { SetValue(MyListProperty, value); }
    }

    public static readonly DependencyProperty MyListProperty = DependencyProperty.Register("MyList", typeof(List<string>), typeof(MyTextBox), new FrameworkPropertyMetadata(new List<string> { "one" }));
}


public class MyConverter : TypeConverter
{
    public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
    {
        if(sourceType == typeof(string))
            return true;
        return base.CanConvertFrom(context, sourceType);
    }

    public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
    {
        if(value is string)
            return new List<string>(((string)value).Split(','));    

        return base.ConvertFrom(context, culture, value);
    }

    public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
    {
        if(destinationType == typeof(string))
            return true;
        return base.CanConvertTo(context, destinationType);
    }

    public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
    {
        if(destinationType == typeof(string))
        {
            var ret = string.Empty; 
            var s = ret;
            ((List<string>)value).ForEach(v => s += s + v + ",");
            ret = ret.Substring(0, ret.Length - 1);

            return ret;
        }

        return base.ConvertTo(context, culture, value, destinationType);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:13:57+00:00Added an answer on May 16, 2026 at 6:13 am

    there is no possibility for doing this with generics, both VS and Blend designers will generate the collection information with those tags while doing design-time serialization. One work around is to create your own data type for MyList instead of List. 🙁

    Or

    You need to keep the MyList as a String property then, parse subsequent strings and store them into a List.

    Or

    One more possible solution. [if you know the values of list earlier]

    Instead of using a List<string> make it an enum with Flags. So, that you can get the expected output syntax in both VS Designer and Blend without those junk codes.

    HTH

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UserControl that I've added a Dependency Property to: public partial class
I have added a custom action to the CustomList type. For testing purposes I
I have a user control that exposes a property of type ImageSource. I want
I am building a project using Maven. In the Pom.xml i have added dependency
I have a WPF ListBox, and I've added some 'FooBar' objects as items (by
I have added some code which compiles cleanly and have just received this Windows
I have added the required assemblies and registered the NVelocityViewFactory in global.asax.cs page but
I have added some dynamic textboxes upon a button click. I need the values
I have added multi-language using the short article below. When you add for example
I have added a parameter to my report with the option Allow Multiple Values

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.