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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:35:27+00:00 2026-06-07T09:35:27+00:00

I am trying to create dynamic controls (Label and combobox) in a WPF form,

  • 0

I am trying to create dynamic controls (Label and combobox) in a WPF form, and have them arranged accordingly. What’s the best practice in doing this and also how do I make the window resize to fit the controls as they grow ?

public MainWindow()
    {
        MyEntities db = new MyEntities();
        InitializeComponent();
        var ID = db.Courses.Where(f => f.CourseId!=null).ToList();
        foreach (var c in ID) 
        {
            ComboBox c = new ComboBox();                
            this.stackpanel.Children.Add(c);
        }
    }            

XAML

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">

    <StackPanel Name= "stackpanel"/>     
</Window>
  • 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-07T09:35:29+00:00Added an answer on June 7, 2026 at 9:35 am

    You can declare ItemsControl and provide item template:

     <ItemsControl ItemsSource="{Binding Collection}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding Name}" />
                     <ComboBox ... />
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    

    As Batuu suggested you can use other controls like ListView to get additional behavor.

    For window growing with your controls list you can use Window.SizeToContent property as was suggested by LPL in comment.

    <Window x:Class="WpfApplication2.MainWindow"
        ...
        SizeToContent="Height">
    

    Available options are described here.

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

Sidebar

Related Questions

So here is the problem: I am trying to create dynamic buttons that have
I'm trying to create a dynamic report in Excel. I have lots of sales
I am trying to create a screen with some dynamic controls, well radio buttons
I'm trying to create a dynamic form builder. Therefore PHP gets a set of
I'm trying to create a dynamic survey form based on dynamic data by using
I am trying to create dynamic pages without creating new files and getting the
I am trying to create dynamic menus from the database using the following example
i'm trying to create a Dynamic Sub-menu to use it in Wordpress, Something like
I am trying to create a dynamic 'page' listing for threads/comments using AJAX. in
I'm trying to create a dynamic point system based off of how much money

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.