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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:55:44+00:00 2026-06-05T15:55:44+00:00

I have the following code. My TreeViewItem: class ComponenteNodoViewModel : BaseViewModel { public string

  • 0

I have the following code.

My TreeViewItem:

class ComponenteNodoViewModel : BaseViewModel
{
    public string Nombre { get; set; }
    private List<ComponenteNodoViewModel> _children;
    private bool _isExpanded;
    private bool _isSelected;


    public ComponenteNodoViewModel Parent { get; set; }


    public bool IsExpanded
    {
        get { return _isExpanded; }
        set
        {
            _isExpanded = value;
            base.RaisePropertyChangedEvent("IsExpanded");
        }
    }

    public bool IsSelected
    {
        get { return _isSelected; }
        set
        {
            _isSelected = value;
            base.RaisePropertyChangedEvent("IsSelected");
        }
    }


    public List<ComponenteNodoViewModel> Children
    {
        get { return _children; }
        set { _children = value; }
    }

}

My ViewModel of the view in which I have the treeView. I have more elements in the GUI, also some bottoms and so on, but I only put the code that has relationship with the treeView.

public List<ComponenteNodoViewModel> ComponenteJerarquia { get; private set; }

...

private void componenteJerarquiaConstruirArbol(List<vComponentesEstructuras> paramNodos)
{

    List<ComponenteNodoViewModel> misNodos = new List<ComponenteNodoViewModel>();

    ComponenteNodoViewModel miNodo = new ComponenteNodoViewModel();
    miNodo.Nombre = "Prueba";
    misNodos.Add(miNodo);
    ComponenteJerarquia = new List<ComponenteNodoViewModel>(misNodos);
}

And finally my xaml of the view:

<UserControl x:Class="GTS.CMMS.Client.Views.ucMaquinasPrincipalView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4"
             xmlns:ViewModels="clr-namespace:Project.ViewModel"
             mc:Ignorable="d"  d:DesignHeight="800" d:DesignWidth="1000">


    <Grid>
        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="232" />
                <ColumnDefinition Width="757" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="309*" />
                <RowDefinition Height="350*" />
            </Grid.RowDefinitions>

            <TreeView ItemsSource="{Binding ComponenteJerarquia}" Margin="6,6,8,5" Name="trvComponente" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <HierarchicalDataTemplate DataType="{x:Type ViewModels:ComponenteNodoViewModel}" ItemsSource="{Binding Path=Children}">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Path=Nombre}"/>
                    </StackPanel>
                </HierarchicalDataTemplate>

                <HierarchicalDataTemplate DataType="{x:Type ViewModels:ComponenteNodoViewModel}">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Path=Nombre}"/>
                    </StackPanel>
                </HierarchicalDataTemplate>         
            </TreeView>                    
        </Grid>
    </Grid>
</UserControl>

The problem is that when I call the componenteJerarquiaConstruirArbol method, the treeview is not populated.

I think that the problem is the binding, but I can’t see the problem.

  • 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-05T15:55:46+00:00Added an answer on June 5, 2026 at 3:55 pm

    The propperty ComponenteJerarquia is just a plain property, so when you set it, the binding system isn’t notified that it needs to update the binding. You need to implement INotifyPropertyChanged in that class and raise the PropertyChanged event in the setter.

    OK, the other part of this is that you shouldn’t be putting your HierarchicalDataTemplates inside your TreeView – that’s making it think you’re trying to put those in the actual tree. Move those templates up to your Resources instead.

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

Sidebar

Related Questions

I have following code: public abstract class Operand<T> { public T Value { get;
Have following code: public interface ITest { string St1 { get; } } public
I have following code: public class reader extends Activity { WebView mWebView; String mFilename;
I have following code I want to test: public class MessageService { private MessageDAO
I have following code for updating user's column public void UpdateLastModifiedDate(string username) { using
I have following code public partial class MainWindow : Window { public MainWindow() {
I have following code that displays an Image with letters, public class MainActivity extends
I have following code in Java: import java.util.*; public class longest{ public static void
I have following code snippet in c#. var list = new List<string> { a,
I have following code: import java.io.*; import java.util.concurrent.* ; public class Example{ public static

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.