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

  • Home
  • SEARCH
  • 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 6064131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:14:48+00:00 2026-05-23T09:14:48+00:00

Learning WPF here and I’m trying to get my head around hierarchical data binding.

  • 0

Learning WPF here and I’m trying to get my head around hierarchical data binding.

This is my situation:

public class A
{
    public int Id { ... }
    public IEnumerable<B> Children { ... }
}

public class B
{
    public string SomeValue { ... }
}

I want to use a ItemsControl to display a collection of A and for each occurance of A I want an inner ItemsControl to display A.Children.

I thought this would do the trick but, apparently, I have much to learn yet…

<ItemsControl x:Name="icCollectionOfAs" ItemsSource="{Binding}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Grid Width="auto" Height="auto">
                <TextBlock Text="{Binding Id}" />
                <ItemsControl ItemsSource="{Binding Children}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding SomeValue}" />
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </Grid>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

Then, in code-behind…

icCollectionOfAs.ItemsSource = createSomeAsWithChildBsInThem();

The result of all this is nothing gets shown. Why?

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-05-23T09:14:49+00:00Added an answer on May 23, 2026 at 9:14 am

    You should not specify the ItemsSource both in XAML (ItemsSource="{Binding}") and code behind (icCollectionOfAs.ItemsSource = createSomeAsWithChildBsInThem();) the XAML might have been called later.

    The rest seems fine to me except that the TextBlock for the ID will probably be hidden behind the ItemsControl for the children as you use a Grid without rows or columns rather than a StackPanel.

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

Sidebar

Related Questions

While learning c# and wpf, i am trying to get grasp of data binding.
Still fooling around with WPF and learning as I go. Trying now to build
I am struggling with the learning curve on WPF data binding and could use
I am currently learning WPF (C#) and have taken the following simple data binding
I am learning on to the concepts of WPF such as data binding, commands,
I'm learning WPF and have been trying to create a toolstrip. Is there a
I'm learning WPF, so I'm kind of n00b in this. I saw some examples
I am learning WPF and am trying to create my first UserControl. My UserControl
I'm learning WPF and MVVM and trying to stress good design. I have lots
I'm learning WPF and XAML. Here is my Form XAML code and the code

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.