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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:16:13+00:00 2026-05-24T17:16:13+00:00

I am new to WPF. I am trying to create a page that is

  • 0

I am new to WPF. I am trying to create a page that is created at run time that is dependent upon a combobox selection. The combobox selection has 2,3,4,5 and the number selected will create a set of text boxes on the next page dynamically.

Should I use a content template or control template or data template with binding and triggers or is there another way to create dynamic textboxes that are dependent on user selection?

  • 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-24T17:16:13+00:00Added an answer on May 24, 2026 at 5:16 pm

    well, i think there is not THE one way to do something like this

    you could use some ItemsControl on the next page and provide it with (at least one) DataTemplate that sets up a TextBox or something else you like to have on the next page …

    here is an example that will add some controls to a ListBox whenever you click on a Button

    XAML:

    <Window x:Class="DynamicPage.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:sys="clr-namespace:System;assembly=mscorlib"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <CollectionViewSource x:Key="VS"/>
        </Window.Resources>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="80"/>
                <ColumnDefinition Width="20"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <StackPanel Orientation="Vertical">
                <Button Content="Add a String" Click="StringButton_Click"/>
                <Button Content="Add a Bool" Click="BoolButton_Click"/>
            </StackPanel>
            <ListBox Grid.Column="2" ItemsSource="{Binding Source={StaticResource VS}}">
                <ListBox.Resources>
                    <DataTemplate DataType="{x:Type sys:String}">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock>I am a String Value</TextBlock>
                            <TextBox Text="{Binding Path=.}"/>
                        </StackPanel>
                    </DataTemplate>
                    <DataTemplate DataType="{x:Type sys:Boolean}">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock>I am an Bool Value</TextBlock>
                            <CheckBox IsChecked="{Binding Path=.}"/>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.Resources>
            </ListBox>
        </Grid>
    </Window>
    

    Code behind:

    using System.Windows;
    using System.Windows.Data;
    using System.Collections.ObjectModel;
    
    namespace DynamicPage
    {
        public partial class MainWindow : Window
        {
            public ObservableCollection<object> MyList = new ObservableCollection<object>();
            public MainWindow()
            {
                InitializeComponent();
                ((CollectionViewSource)this.Resources["VS"]).Source = MyList;
            }
    
            private void StringButton_Click(object sender, RoutedEventArgs e)
            {
                MyList.Add("Some Text");
            }
            private void BoolButton_Click(object sender, RoutedEventArgs e)
            {
                MyList.Add(false);
            }
        }
    }
    

    as you can see I only have a Collection of objects, and I add bools and Strings …

    the datatemplate gets selected based on the Type of the Object (you could use your own Types here instead of primitives)

    so for creating controls on another page/window, you could setup a collection of View-Models, bind that to an ItemsControl, and have a DataTemplate for each Type instead of creating every control on your own with code behind …

    but this is only one way to do that … not necessarily THE way

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

Sidebar

Related Questions

I am new to WPF and am trying to create a WPF control that
Just new in WPF, I'm trying to do a combobox that allows people to
I am new to WPF. I'm trying to build an application which has a
I have a WPF application where I'm trying to create a diagnostics panel that's
I am trying to create a new WPF control called NumericTextBox . It inherits
I'm new to WPF/C#, and I'm trying to create a simple sql query application
I am trying to create a WPF application that will be a central point
I'm new to WPF and I'm trying to create an UserControl which will have
I am trying to create a basic WPF application that can store an encrypted
I am trying to create dynamic controls (Label and combobox) in a WPF form,

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.