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

  • SEARCH
  • Home
  • 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 8411603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:27:44+00:00 2026-06-10T00:27:44+00:00

I have a class with a List<string> Tags that I want to display in

  • 0

I have a class with a List<string> Tags that I want to display in a TextBox. For this I use a IValueConverter.

ListToStringConverter:

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
    var list = value as List<string>;
    var returnvalue = string.Empty;

    if(list != null)
        list.ForEach(item => returnvalue += item + ", ");
    return returnvalue;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
    var strValue = value as string;

    if(strValue != null)
        return strValue.Split(new char[] { ',' });

    return null;
}

Class Test:

public class Test : IDataErrorInfo
{
    public Test()
    {
        Tags = new List<string>();
    }

    public List<string> Tags { get; set; }

    string errors;
    const string errorsText = "Error in Test class.";
    public string Error
    {
        get { return errors; }
    }

    public string this[string propertyName]
    {
        get 
        {
            errors = null;
            switch (propertyName)
            {
                case "Tags":
                    if (Tags.Count <= 1)
                    {
                        errors = errorsText;
                        return "...more tags plz..";
                    }
                    break;
            }
            return null;
        }
    }
}

Now I want to Validate the Tags:

<TextBox Text="{Binding Test.Tags, Converter={StaticResource ListToStringConverter}, Mode=TwoWay, ValidatesOnDataErrors=True}" />

But there is no error displayed. Maybe because of the conversion but how can i still accomplish a validation?

  • 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-06-10T00:27:45+00:00Added an answer on June 10, 2026 at 12:27 am

    I don’t see why it shouldn’t work. If you will run this at first time – SL will highlight the TextBox with red border. But if you will try to change the list of tags – you will see nothing, because you in your converter you have a bug in ConvertBack you return type array of strings (string[]), but property expects object with type List, so you just need to update the ConvertBack method to:

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        var strValue = value as string;
    
        if (strValue != null)
            return strValue.Split(new char[] { ',' }).ToList();
    
        return null;
    }
    

    One more note about Convert method, you can use Join method:

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        var list = value as List<string>;
        if (list != null)
            return String.Join(", ", list);
        return null;
    }
    

    And one more thing about combining the strings. Don’t use operator +, because you can have performance issues with it, use StringBuilder instead.

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

Sidebar

Related Questions

I have this class: class OriginalClass { string FirstItem; List<string> ListOfSecondItems; } I want
Given that I have the following WCF service: class LookUpService { public List<County> GetCounties(string
I have a list of this class: public class Data { public string name
I have a list of parameters like this: public class parameter { public string
I have a class class PCB { public: struct { string type; **linklist list;**//refer
I have the following C# class: public class SomeClass{ public string Name; public List<SomeClass>
I have 2 classes with this structure: class ClassA { String typeA; List<String> valuesA;
I have a document class that contains a list of tags. Something like: class
i have this model on mvc: public class User { public string Name {
I have the following code: class Employee { friend string FindAddr( list<Employee> lst,string name

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.