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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:20:41+00:00 2026-05-15T11:20:41+00:00

In C# (or in C# with WPF), how would I build a checkbox at

  • 0

In C# (or in C# with WPF), how would I build a checkbox at run time?
I would I be able to query the check box to see if the user clicked on it?

In other words, suppose I have a “grid” on which I want to have displayed some checkboxes. But I do not know how many checkboxes to display. I suppose I could (in WPF) fill the grid with checkboxes at design time and mark them as hidden (or visibly == false) and then show them at run time. But I was hoping there was a more elegant way to do this.

  • 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-15T11:20:41+00:00Added an answer on May 15, 2026 at 11:20 am

    There are several ways to do this in WPF. A quick and dirty approach would be to do something like this:

    <StackPanel x:Name="CheckBoxes" />
    

    Then in your code behind do:

    for (int i=0; i < 10; i++) {
        this.CheckBoxes.Children.Add(new CheckBox());
    }
    

    But while at first glance it looks simple, this makes it somewhat of a pain to work with in the long run. Instead, a better solution would be to have a class that has a boolean property such as:

    // this should really implement INotifyPropertyChanged but
    // we'll ignore that for now...
    public class SelectableThing {
    
        public bool IsSelected {
            get;
            set;
        }
    
        public string Description {
            get;
            set;
        }
    
    }
    

    Then in your XAML, you would have a bindable control such as ItemsControl:

    <ItemsControl x:Name="CheckBoxes">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}"
                          Content="{Binding Description}" />
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
    

    Then in your code behind you could create a collection of these SelectableThing’s and set them as the ItemsSource.

    private SelectableThing[] things;
    
    // where you do this is up to you really
    private void Window_Load(object sender, RoutedEventArgs e) {
    
        things = new SelectableThing[] {
            new SelectableThing("First Thing"),
            new SelectableThing("Second Thing"),
            new SelectableThing("Third Thing")
        };
    
        CheckBoxes.ItemsSource = things;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Still fooling around with WPF and learning as I go. Trying now to build
I would like to build a generic/re-usable modal dialog that I can use in
I would like to avoid having to build a menu manually in XAML or
I'm trying to build a WPF DrawingBrush that will draw a hatch pattern using
I need to build a WPF control that looks somehow similar to this: alt
I would like to copy to clipboard what a Control of my WPF app
I'm new to WPF and before I dive in solving a problem in completely
I am currently playing around with WPF and the WPF toolkit which contains a
WPF launches certain method which calls external exe and waits , and then accesses
I have to build a number of small independent applications, that can be copied

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.