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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:54:41+00:00 2026-05-29T05:54:41+00:00

I have a little WPF app, that has a TreeView to display hierarchical data.

  • 0

I have a little WPF app, that has a TreeView to display hierarchical data. I’ve created a ViewModel to represent the data to be displayed. Actually there are a couple of concrete ViewModels, because I have different kind of objects on various levels of the hierarchy.

public abstract class TreeViewModelBase
{
    private bool _isSelected;
    public bool IsSelected
    {
        get { return _isSelected; }
        set
        {
            if (value == _isSelected) return;

            _isSelected = value;
            OnItemSelected(this, new TreeViewModelSelectedEventArgs(this));
            RaisePropertyChanged(() => IsSelected);
        }
    }
}

So in order to add a new node to the three I just add a new ViewModel object and let the databinding do it’s magic to update the tree. I also wanted to make the recently added node the selected node, so I set the IsSelected property to true.

public class FooTreeViewModel : TreeViewModelBase
{
    public ObservableCollection<BarTreeViewModel> Bars { get; private set; }
    public void AddNewPage(Bar newBar)
    {
        var newBarTreeViewModel = new BarTreeViewModel(newBar);
        Bars.Add(newBarTreeViewModel);
        newBarTreeViewModel.IsSelected = true;
    }
}

But this is where I seem to have some trouble. I observe that IsSelected for my recently added object is being executed, but just a second later IsSelected for the previous item is being executed. This seems weird to me.

Although the tree is updated correctly, the SelectedItem of the tree points still to the previous node, not the recently added node which was marked with the IsSelected.

Any hints on what I might be missing?

  • 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-29T05:54:42+00:00Added an answer on May 29, 2026 at 5:54 am

    OK; sometimes all it takes is to talk with someone about the problem. After I wrote this post I figured: the IsSelected property is called twice, first for the IsSelected=true for the recently added node and the IsSelected=false on the previously selected node. Because I always raise the OnSelectedItem event (which causes the ViewModel to figure out which node is currently selected) the last call wins – which is the previous node. So by changing the code to only call OnSelectedItem when _isSelected is true, this fixed my code.

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

Sidebar

Related Questions

i have little problem with boost::asio library. My app receive and process data asynchronously,
I have successfully created a asp mvc app which basically has interface, service and
I have a WPF app that from time to time needs to perform a
(WPF) We have been asked to build a little window that pops up when
I have a frame control in a WPF app which has an HTML page
So I have a little WPF XAML that gets the titles of my RSS
i have little dilemma, i often use data-bound controls such as Gridview in conjunction
I have a MainMenu in my app and I would like to have little
We have a C# client app that communicates to our C# backend service via
I have a simple little application that performs some analysis of all our corporate

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.