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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:03:10+00:00 2026-06-03T06:03:10+00:00

This is an interesting case to which I haven’t been able to find any

  • 0

This is an interesting case to which I haven’t been able to find any info online. I am trying to create a grid and need to bind an ObservableCollection of ObservableCollection to it. Imagine a model such as this:

public class App
{
    private ObservableCollection<MyNewCollection> collections;
}

public class MyNewCollection : DependencyObject
{
    public ObservableCollection<MyCollectionItem> items;
    // ... public properties: string CollectionTitle 
}

public class MyCollectionItem : DependencyObject 
{
    // ... public properties: string ItemTitle
}

I want the first column of the grid to list items in collections object so that every row would contain the CollectionTitle from one of the items in the collections ObservableCollections. For the second column, I want each row to contain the set of MyCollectionItems items associated with the appropriate collection object.

From the code above:

  1. collections as ‘c’
  2. items as ‘i’
+---------------------------------------------------------------------------------------------+
+        |       Column 0          |                        Column 1                          |
+---------------------------------------------------------------------------------------------|
+ Row 0  |  c[0].CollectionTitle   | c[0].i[0].ItemTitle ...i[1].ItemTitle ... i[2].ItemTitle |
+ Row 1  |  c[1].CollectionTitle   | c[1].i[0].ItemTitle ...i[1].ItemTitle ... i[2].ItemTitle |
+        |                         |                                                          |
+ ...                                                                                         |
+---------------------------------------------------------------------------------------------+

This would have been easy if I had a static set of MyNewCollection objects but since that can grow to infinity, I need to create a new ObservableCollection of the MyNewCollection objects and this is where I am running into trouble in understanding how to do this with WPF. Any help will be appreciated.

Thanks.

  • 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-03T06:03:11+00:00Added an answer on June 3, 2026 at 6:03 am

    Here’s one way using an ItemsControl where each row contains another ItemsControl.

    The Xaml:

    <Page.Resources>
        <DataTemplate x:Key="ChildItemTemplate" 
                      DataType="{x:Type Samples:NestedCollectionItem}">
            <TextBlock Text="{Binding Title}" Margin="5"/>
        </DataTemplate>
        <ItemsPanelTemplate x:Key="ChildItemPanel">
            <StackPanel Orientation="Horizontal"/>
        </ItemsPanelTemplate>
        <DataTemplate x:Key="ItemTemplate" 
                      DataType="{x:Type Samples:NestedCollectionChildViewModel}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" SharedSizeGroup="c1"/>
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <TextBlock VerticalAlignment="Center"  Text="{Binding Title}"/>
                <ItemsControl 
                    Grid.Column="1" 
                    ItemsSource="{Binding Items}"
                    ItemsPanel="{StaticResource ChildItemPanel}"
                    ItemTemplate="{StaticResource ChildItemTemplate}"
                    />
            </Grid>
        </DataTemplate>
    </Page.Resources>
    
    <Page.DataContext>
        <Samples:NestedCollectionRootViewModel/>
    </Page.DataContext>
    
    <Grid>
        <ItemsControl 
            Grid.IsSharedSizeScope="True"
            ItemsSource="{Binding Items}" 
            ItemTemplate="{StaticResource ItemTemplate}"/>
    </Grid>
    

    The code:

    public class NestedCollectionRootViewModel
    {
        public NestedCollectionRootViewModel()
        {
            Items =
                new ObservableCollection<NestedCollectionChildViewModel>
                    {
                        new NestedCollectionChildViewModel
                            {
                                Title = "Item 1",
                                Items =
                                    new ObservableCollection<NestedCollectionItem>
                                        {
                                            new NestedCollectionItem {Title = "One"},
                                            new NestedCollectionItem {Title = "Two"},
                                            new NestedCollectionItem {Title = "Three"},
                                            new NestedCollectionItem {Title = "Four"},
                                        }
                            },
    
                        new NestedCollectionChildViewModel
                            {
                                Title = "Item 2",
                                Items =
                                    new ObservableCollection<NestedCollectionItem>
                                        {
                                            new NestedCollectionItem {Title = "Five"},
                                            new NestedCollectionItem {Title = "Six"},
                                        }
                            },
    
                    };
        }
    
        public ObservableCollection<NestedCollectionChildViewModel> Items 
           { get; private set; }
    }
    
    public class NestedCollectionChildViewModel
    {
        public string Title { get; set; }
        public ObservableCollection<NestedCollectionItem> Items { get; set; }
    }
    
    public class NestedCollectionItem
    {
        public string Title { get; set; }
        // ... etc
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have been reading this interesting article which is increasing my every growing confusion
I have a really interesting case: I have a site where this is already
There is this interesting game, that has numbers in a grid, where each number
For years I've been following a great pattern called Target-Action which goes like this:
In this case I have some code which is working without problem in an
I was digging around in MSDN and found this article which had one interesting
I have run into an interesting issue using PHP's date() function. Haven't had any
I have been trying to make this work for a long time now. In
I found this interesting behavior. Why could this happen I am using the cmdlet
I was reading this interesting post on metaclasses What is a metaclass in Python?

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.