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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:40:36+00:00 2026-05-13T11:40:36+00:00

I have a treeview which binds to lots of nested ObservableCollections. Each level of

  • 0

I have a treeview which binds to lots of nested ObservableCollections. Each level of the treeview shows an aggregated sum of all the hours in child items. For example:

Department 1, 10hrs
  ├ Team 10, 5hrs  
  │  ├ Mark, 3hrs
  │  └ Anthony, 2hrs   
  └ Team 11, 5hrs
     ├ Jason, 2hrs
     ├ Gary, 2hrs
     └ Hadley, 1hrs  
Department 2, 4hrs   
  ├ Team 20, 3hrs  
  │  ├ Tabitha, 0.5hrs
  │  ├ Linsey, 0.5hrs
  │  └ Guy, 2hrs
  └ Team 11, 1hr
     └ "Hadley, 1hr"  

When I modify my Individual.Hours in my ViewModel class i want to update the hours
values in both my team and departments too.

I’m already using NotificationProperties for all my Hours properties, and ObservableCollections for Teams in Departments and Individuals in Teams.

Thanks,
Mark

  • 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-13T11:40:36+00:00Added an answer on May 13, 2026 at 11:40 am

    Each department’s hours depends on the aggregate of its team’s hours. Each team’s hours depends on the aggregate of its individual’s hours. Thus, each Team should listen for changes to any of its individual’s Hours property. When detected, it should raise OnPropertyChanged for its own Hours property. Similarly, each Department should listen for changes to any of its team’s Hours property. When detected, it should raise OnPropertyChanged for its own Hours property.

    The end result is that changing any individual’s (or team’s) hours is reflected in the parent.

    Pseduo code that can be greatly improved with refactoring but gives the essence of the answer:

    public class Individual : ViewModel
    {
        public int Hours
        {
            // standard get / set with property change notification
        }
    
    }
    
    public class Team : ViewModel
    {
        public Team()
        {
            this.individuals = new IndividualCollection(this);
        }
    
        public ICollection<Individual> Individuals
        {
            get { return this.individuals; }
        }
    
        public int Hours
        {
            get
            {
                // return sum of individual's hours (can cache for perf reasons)
            }
        }
    
        // custom collection isn't strictly required, but makes the code more readable
        private sealed class IndividualCollection : ObservableCollection<Individual>
        {
            private readonly Team team;
    
            public IndividualCollection(Team team)
            {
                this.team = team;
            }
    
            public override Add(Individual individual)
            {
                individual.PropertyChanged += IndividualPropertyChanged;
            }
    
            public override Remove(...)
            {
                individual.PropertyChanged -= IndividualPropertyChanged;
            }
    
            private void IndividualPropertyChanged(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "Hours")
                {
                    team.OnPropertyChanged("Hours");
                }
            }
        }
    }
    
    public class Department : ViewModel
    {
        public Department()
        {
            this.teams = new TeamCollection();
        }
    
        public ICollection<Team> Teams
        {
            get { return this.teams; }
        }
    
        public int Hours
        {
            get
            {
                // return sum of team's hours (can cache for perf reasons)
            }
        }
    
        // TeamCollection very similar to IndividualCollection (think generics!)
    }
    

    Note that if performance becomes an issue you can have the collection itself maintain the hour total. That way, it can do a simple addition whenever a child’s Hours property changes, because it is told the old value and the new value. Thus, it knows the difference to apply to the aggregate.

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

Sidebar

Related Questions

I have a TreeView which uses a HierarchicalDataTemplate to bind its data. It looks
I have an application which shows a Tree where can select nodes of the
I have a TreeView which i build up in code recursively. I would like
Ok, I have a treeview which I am using to display a number of
So basically i have 2 treeviews running next to each other, one shows a
I have a TreeView which I have bound to a ViewModel called RootViewModel which
I have a Treeview which is doing lazy loading. I used MVVM. I wanted
I have a WPF TreeView which displays my ViewModel. I have a button that
I have a TreeView in WPF which I have bound to a collection of
I am creating a treeview which wil have folder images for directories and want

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.