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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:02:41+00:00 2026-05-17T16:02:41+00:00

I am relatively new to the Silverlight experience and am trying to create a

  • 0

I am relatively new to the Silverlight experience and am trying to create a MVVM app with a DomainService that returns POCOs as the models. I have a UserControl that has a TreeView with the ItemsSource set to bind to an ObservableCollection of a type that has an ObservableCollection as one of it’s properties, and that collection is of a type that has a property of ObservableCollection. So I’m using the HierarchicalDataTemplate as the ItemTemplate of the TreeView with TextBlocks to render the Name property of each item. I will include some code below.

So the classes would be something like this:

public class A
{
    public int ID { get; set; }
    public string Name { get; set; }
    public ObservableCollection<B> Bs { get; set; }
}

public class B
{
    public int ID { get; set; }
    public string Name { get; set; }
    public ObservableCollection<C> Cs { get; set; }
}

public class C
{
    public int ID { get; set; }
    public string Name { get; set; }
}

Basically, my collections are getting populated from a DataRepository with a method that gets lists of A,B, and C. Adds each instance appropriately with LINQ through foreach loops. And returns a List. The method works correctly as I have called it from the default.aspx.cs and stepped through to confirm that all data is correctly added.

But my problem is that when it is rendered on the screen, none of the collections are correct. For instance, the first item of “A”‘s child collection of “B” should have a count of over 4000 and yet none are shown. And yet, the first item of “B” that is supposed to be in the collection “Bs” of the first “A” is shown for the second item of “A”.

(example of what it should be)

  • a1

    • b1.1
      • c1.1.1
      • c1.1.2
      • c1.1.3
    • b1.2
      • c1.2.1
      • c1.2.2
  • a2

    • b2.4
      • c2.4.1
      • c2.4.2
      • c2.4.3
  • a3

    • b3.6
      • c3.6.1
      • c3.6.2
      • c3.6.3
  • a4

    • b4.8
      • c4.8.1
      • c4.8.2
      • c4.8.3

(example of what it is showing)

  • a1
  • a2
    • b2.2
      • c2.2.2
  • a3
  • a4
    • b4.4
      • c4.4.4

After some investigation, the only pattern that I see is that the hierarchy is based on the ID’s being the same.

Here are the code samples:

(the DataContext is set by a UserControl Resource)

<sdk:TreeView ItemsSource="{Binding Path=As}" >
 <sdk:TreeView.ItemTemplate>`  
  <sdk:HierarchicalDataTemplate ItemsSource="{Binding Path=Bs}">
   <TextBlock Text="{Binding Path=Name}" />
   <sdk:HierarchicalDataTemplate.ItemTemplate>
    <sdk:HierarchicalDataTemplate ItemsSource="{Binding Path=Cs}">
     <TextBlock Text="{Binding Path=Name}" />
     <sdk:HierarchicalDataTemplate.ItemTemplate>
      <sdk:HierarchicalDataTemplate ItemsSource="{Binding}">
       <TextBlock Text="{Binding Path=Name}" />
      </sdk:HierarchicalDataTemplate>
     </sdk:HierarchicalDataTemplate.ItemTemplate>
    </sdk:HierarchicalDataTemplate>
   </sdk:HierarchicalDataTemplate.ItemTemplate>
  </sdk:HierarchicalDataTemplate>
 </sdk:TreeView.ItemTemplate>
</sdk:TreeView>

ViewModel

public class myViewModel
{
    private myDomainContext context = new myDomainContext();

    public ObservableCollection<A> As
    {
        get
        {
            LoadOperation<A> loadOp = context.Load(context.GetAsQuery());
            return new ObservableCollection<A>(loadOp.Entities);
        }
    }
}

I apologize about the length of this question, I was hoping to not be so vague and to get some helpful advise. This issue has been plaguing me for a few days now and I’m sooo ready to move on. Please help me get out of the muck. Thanks in advance. And if you have any good links that would be helpful for my MVVM knowledge I would greatly appreciate them as well.

My Environment is:
– Asp.Net 4
– Silverlight 4
– VisualStudio 2010

  • 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-17T16:02:42+00:00Added an answer on May 17, 2026 at 4:02 pm

    I was under the impression that a HierarchicalDataTemplate is used hierarchically 🙂 That is, you use one only and it recursively applies to any children.

    This does mean that the data keys must be related and the data uniform (of the same type).

    The template you have described above is basically nesting 3 templates inside each other, so you get the first record of each displayed (where there is child data).

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

Sidebar

Related Questions

I am relatively new to Silverlight development and I am trying to figure out
I'm new to Silverlight and I wanted to accomplish a relatively simple task:    Create
I have a class in my Silverlight app that (de-)serializes JSON strings to/from an
Relatively new to rails and trying to model a very simple family tree with
I'm relatively new to Nant, what i'd like to do is have a task
I'm new to Silverlight programming, and the DependencyProperty is still relatively new to me,
Relatively new to JQuery. I've got some code that does a banner swap with
Relatively new to dealing with XML in jQuery. I am trying to retrieve a
Relatively new to python. I recently posted a question in regards to validating that
Trying to code a Windows Phone silverlight app, and I'm trying to copy a

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.