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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:17:29+00:00 2026-05-16T08:17:29+00:00

I’m still somewhat new to WPF (only done a few small projects with it).

  • 0

I’m still somewhat new to WPF (only done a few small projects with it). I’m trying to make a repeating group of controls (user can add/remove these groups), databound to a custom class. Example UI:

([UserButton1] [UserButton2]) <--each of these () is a separate group of buttons
([Cheese]      [Wine]       )
([Wallace]     [Gromit]     )
                        [Add] <--this button can add more groups

databound to a list of a class like this (pseudocode):

class UserButtons {
    string UserButton1 = "UserButton1"
    string UserButton2 = "UserButton2"
}

such as

List<UserButtons> = {
    [0]: UserButton1, UserButton2
    [1]: Cheese, Wine
    [2]: Wallace, Gromit
}

I know this is the sort of thing WPF was created to do, but I can’t quite figure out exactly how to go about it.

Should I use some sort of ListView? Would a DataTemplate help? A StackPanel sounds OK, but it doesn’t have databinding for a list…or does it? And I’m not even sure how to make databinding work for the groups of buttons like indicated above (if that even made sense to you…sorry for the bad example). Does anyone have any insight on this problem?

I searched to try to find a question pertaining to this and didn’t see one, perhaps because I wasn’t sure what to search for. So, sorry if it’s an unintended dupe.

  • 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-16T08:17:30+00:00Added an answer on May 16, 2026 at 8:17 am

    I’m not entirely sure what you’re looking for but I hope the example below helps. I used an ItemsControl whose ItemsSource is set to the collection of UserButtons. Its ItemTemplate property is set to a StackPanel that shows two buttons, the Content property of each is bound to properties in UserButtons.

    XAML:

    <Window x:Class="WpfApplication3.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:WpfApplication3"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
    
        </Window.Resources>
    
        <StackPanel Orientation="Vertical">
            <ItemsControl x:Name="itemsControl" Background="LightBlue">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <Button Content="{Binding Button1}" Width="100"/>
                            <Button Content="{Binding Button2}" Width="100"/>
                        </StackPanel>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
    
            <Button Width="50" Click="Button_Click">Add</Button>
    
        </StackPanel>
    
    </Window>
    

    Code-Behind:

    public partial class MainWindow : Window
    {
        ObservableCollection<UserButtons> oc;
    
        public MainWindow()
        {
            InitializeComponent();
    
            oc = new ObservableCollection<UserButtons>()
            {
                new UserButtons() { Button1="UserButton1", Button2 = "UserButton2"},
                new UserButtons() { Button1="Cheese", Button2 = "Wine"},
                new UserButtons() { Button1="Wallace", Button2 = "Gromit"},
            };
    
            this.itemsControl.ItemsSource = oc;
        }
    
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            oc.Add(new UserButtons() { Button1 = "NewButton1", Button2 = "NewButton2" });
        }
    }
    
    public class UserButtons : INotifyPropertyChanged
    {
        private string button1;
        public string Button1
        {
            get { return this.button1; }
            set
            {
                this.button1 = value;
                this.OnPropertyChanged("Button1");
            }
        }
    
        private string button2;
        public string Button2
        {
            get { return this.button2; }
            set
            {
                this.button2 = value;
                this.OnPropertyChanged("Button2");
            }
        }
    
        #region INotifyPropertyChanged Members
    
        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string propName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
            }
        }
    
        #endregion
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.