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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:41:23+00:00 2026-06-13T12:41:23+00:00

I am working on a WPF where I need to dynamically generate Checkboxes 16

  • 0

I am working on a WPF where I need to dynamically generate Checkboxes 16 times.

XAML:

<Checkboxes Height="14" Command="{Binding CheckboxesGen}" Margin="0" Name="checkBox1" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center" />

Using above way, It will be inefficient if I write down this Checkboxes 16 times and have individual Button Click Command for them. I would ideally want to generate them 16 times and have one common method in my viewmodel class as follows:

private ICommand mCheckboxesGen;
    public ICommand CheckboxesGen
    {
        get
        {
            if (mCheckboxesGen== null)
                mCheckboxesGen= new DelegateCommand(new Action(mCheckboxesGenExecuted), new Func<bool>(mCheckboxesGenCanExecute));

            return mCheckboxesGen;
        }
        set
        {
            mCheckboxesGen= value;
        }
    }

    public bool mCheckboxesGenCanExecute()
    {
        return true;
    }

    public void mCheckboxesGenExecuted(some INDEX parameter which gives me selected Checkboxes )
    {
        // Have a common method here which performs operation on each Checkboxes click based on INDEX which determines which Checkboxes I have selected
    }

I had faced the same situation in my C++ app. I had done it in my C++ app as follows:

for(int j = 0; j < 16; j ++)
    {
        m_buttonActiveChannels[j] = new ToggleButton();
        addAndMakeVisible(m_buttonActiveChannels[j]);
        m_buttonActiveChannels[j]->addButtonListener(this);
    }

//Checking which Checkboxes is clicked
unsigned bit = 0x8000;
for(int i = 15; i >= 0; i--)
{
    if(0 != (value & bit)) //Value has some hardcoded data
    {
        m_buttonActiveChannels[i]->setToggleState(true);
    } 
    else
    {
        m_buttonActiveChannels[i]->setToggleState(false);
    }

    bit >>= 1;
}

Hence using this generates it 16 times and has one method which performs operation based on index i.

Using a similar approach or any other approach, How can I achieve it in my wpf app? 🙂
Please help 🙂

  • 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-13T12:41:24+00:00Added an answer on June 13, 2026 at 12:41 pm

    How about something like this?

    <ItemsControl ItemsSource="{Binding CollectionOfObjectsThatRepresentYourCheckBox}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal"
                            IsItemsHost="True" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Checkbox Content="{Binding DisplayText }" Checked="{Binding Checked}" />
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
    

    you would need to populate your collection on objects on load or when a command was executed, then you could react to items being checked in the model that you create for it..

    public class CheckBoxClass
    {
     public int Index {get; set;}
     public string DisplayText {get; set}
     private bool _checked;
     public bool Checked 
     {
       get { return _checked;}
       set {
            _checked = value
            doSomethingWhenChecked();
           }
    }
    
    ObservableCollection<CheckBoxClass> CollectionOfObjectsThatRepresentYourCheckBox = SomeMethodThatPopulatesIt();
    

    this is a much cleaner way to do this and instead of generating the controls you will be just binding to a list of your objects that will be represented by a check box.

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

Sidebar

Related Questions

I am working on a WPF where I need to dynamically generate Togglebutton 16
I am working on a WPF application where I need to dynamically generate 2
I'm working in WPF and i have an interesting requirement. I need my checkboxes
I am working in WPF and I need to set the Text and ToolTip
I have been working on a C# 4.0 WPF project and need to figure
I am working on a wpf application. Here I need to use System.Windows.Forms.FolderBrowserDialog in
I'm working with WPF and often have the need to get the namespace and
Ok been working with WPF for a while but I need some help. I
I am working on a WPF app where I need to work with comboboxes.
I'm working with the WPF Extended Toolkit's Property Editor, and I need to add

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.