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 4545290
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:47:34+00:00 2026-05-21T15:47:34+00:00

I have a List<String> in a custom user control. Whenever the List<String> is modified,

  • 0

I have a List<String> in a custom user control. Whenever the List<String> is modified, I want the custom user control to have checkboxes for every item in the List<String>. My original idea (being used to Java) was to just add the checkboxes and remove them directly.

But… I know C# can do better than that. Is there some way I can “bind” the strings to the UI so they show up as checkboxes? (or any other method that works?)

  • 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-21T15:47:35+00:00Added an answer on May 21, 2026 at 3:47 pm

    You can do that easily by binding an ItemsControl to the list of strings:

    <ItemsControl ItemsSource="{Binding Strings}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <CheckBox Content="{Binding}" />
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
    

    However that’s not very useful, because you have no easy way to access the state of the CheckBox… A better option would be to wrap the string in a class that also exposes a bool property:

    public class CheckableItem<T> : INotifyPropertyChanged
    {
        public CheckableItem(T value)
        {
            _value = value;
        }
    
        private T _value;
        public T Value
        {
            get { return _value; }
            set
            {
                _value = value;
                OnPropertyChanged("Value");
            }
        }
    
        private bool _isChecked;
        public bool IsChecked
        {
            get { return _isChecked; }
            set
            {
                _isChecked = value;
                OnPropertyChanged("IsChecked");
            }
        }
    
        public event PropertyChangedEventHandler PropertyChanged;
    
        protected virtual void OnPropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
                handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    

    You can then expose a list of CheckableItem<string> instead of a list of strings, and change the XAML as follows:

    <ItemsControl ItemsSource="{Binding Items}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <CheckBox Content="{Binding Value}" IsChecked="{Binding IsChecked}" />
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
    

    If you need to test if the CheckBox is checked, just test the IsChecked property in the CheckableItem<T> class.

    If you need the CheckBox to have 3 states (checked/unchecked/indeterminate), just declare IsChecked as bool? instead of bool.

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

Sidebar

Related Questions

I have a two dependency properties(both List of strings) in a custom user control.The
I have a list of string values that I want add to a hashtable
I have a list of string like: s = [(abc,bcd,cde),(123,3r4,32f)] Now I want to
I have a list: List(Of String) I want to filter it with LINQ. I
I have a table view that displays a list that I want the user
I have a custom control with a generic list of custom types. This list
I currently have a custom listview where each item on the list contains two
I have a dictionary which is keyed by a List: private Dictionary<List<custom_obj>, string> Lookup;
I have List[(String,String)] and I need to sort them by the 2nd value and
I have a List of String objects that are pipe delimited. something like this:

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.