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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:56:38+00:00 2026-06-06T03:56:38+00:00

I want to bind Groupboxes to my stackpanel. c#: internal ObservableCollection<GroupBox> BindingTest { get

  • 0

I want to bind Groupboxes to my stackpanel.

c#:

internal ObservableCollection<GroupBox> BindingTest
{
    get
    {
        ObservableCollection<GroupBox> collection = new ObservableCollection<GroupBox>();
        for (int counter = 0; counter < 5; counter++)
        {
            GroupBox groupBox = new GroupBox();
            groupBox.Header = " ... Header ... ";
            groupBox.Content = " ... Content ... ";
            collection.Add(groupBox);
        }

            return collection;
    }
}

and the xaml code:

<StackPanel x:Name="Dynamic" Grid.Row="1" Margin="29,118,6,0">
    <ItemsControl ItemsSource="{Binding Path=BindingTest}" Height="482">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <GroupBox>
                    <GroupBox.Header>{Binding Path=Header}</GroupBox.Header>
                    <GroupBox.Content>{Binding Path=Content}</GroupBox.Content>
                </GroupBox>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</StackPanel>

where does my error in reasoning?

  • 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-06T03:56:40+00:00Added an answer on June 6, 2026 at 3:56 am

    In WPF Binding, you usually don’t bind to Controls, you just bind to objects and let the Markup handle UI details. Ideally your objects should implement INotifyPropertyChanged to notify the Binding of property changes. Control creation is handled already by the DataTemplate, it already creates a GroupBox for you and binds its properties to the properties of the object used in the binding.

    Your ViewModel should, if possible, not know anything about the UI, or use any Controls. The MVVM pattern is meant to decouple UI and Data/Logic.

    The class of your data objects could look something like this:

    public class DataObject : INotifyPropertyChanged
    {
        private string header;
        private string content;
    
        public string Header {
            get { return header; }
            set { header = value; RaisePropertyChanged("Header"); }
        }
    
        public string Content {
            get { return content; }
            set { content= value; RaisePropertyChanged("Content"); }
        }
    
        public event PropertyChangedEventHandler PropertyChanged;
    
        protected void RaisePropertyChanged(string propertyName) {
            var handler = PropertyChanged;
            if (handler != null) { 
                handler(this, new PropertyChangedEventArgs(propertyName)); 
            }
        }
    }
    

    The property you bind to would also look different:

    internal ObservableCollection<DataObject> BindingTest
    {
        get
        {
            ObservableCollection<DataObject> collection = new ObservableCollection<DataObject>();
            for (int counter = 0; counter < 5; counter++)
            {
                DataObject item = new DataObject ();
                item.Header = " ... Header ... ";
                item.Content = " ... Content ... ";
                collection.Add(item );
            }
    
                return collection;
        }
    }
    

    I assume creating a new Collection every time the property is accessed is just for testing purposes.

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

Sidebar

Related Questions

Using WPF, I want to bind the header of a GroupBox to the typename
I've got a collection of ViewModels and want to bind a ListBox to them.
I want to bind a content of a Label to the SelectedItem of a
I want to bind combobox to value only and distinct name .But I get
I want to bind a 2 dimensional collection - collection of collection of complex
I want to bind my UI against a collection of XElements and their properties
I want to bind my window's height to the StackPanel's height. What is the
I want to bind a XML content as a String to the field. Here
I want to bind my ListView control to a generic list of objects? I
I want to bind Ctrl-Alt-N to an External Tool (Nant build) in SharpDevelop, how

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.