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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:45:56+00:00 2026-06-12T01:45:56+00:00

I have been trying to make a treeview that looks something like 2001(root) -Student1(node)

  • 0

I have been trying to make a treeview that looks something like

2001(root)

-Student1(node)
-Student2(node)

I’ve tried to use hierarchicaldatatemplates but I’m still not grasping what I need to. This is my code that i’m looking to bind my treeview to. Any help with the Xaml would be appriciated.

I thought it would look something like

    <TreeView ItemsSource="{Binding CurrentClass}">
        <TreeView.Resources>
            <HierarchicalDataTemplate DataType="{x:Type local:Student}" ItemsSource="{Binding CurrentClass.Students}">
                    <TextBlock Text="{Binding CurrentClass.Students/FirstName}" />
                </HierarchicalDataTemplate>
        </TreeView.Resources>
    </TreeView>
public class ViewModel
{
    public FreshmenClass currentClass = new FreshmenClass();

    public ViewModel()
    {
        currentClass.Year = "2001";
        currentClass.Students.Add(new Student("Student1", "LastName1"));
        currentClass.Students.Add(new Student("Student2", "LastName2"));
    }

    public FreshmenClass CurrentClass
    {
        get { return currentClass; }
    }
}

public class FreshmenClass
{
    public string Year { get; set; }
    public List<Student> students = new List<Student>();

    public List<Student> Students
    {
        get { return students; }
        set { students = value; }
    }
}

public class Student
{
    public string FirstName { get; set; }
    public string LastName { get; set; }

    public Student(string firstName, string lastName)
    {
        FirstName = firstName;
        LastName = lastName;
    }
}
  • 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-12T01:45:57+00:00Added an answer on June 12, 2026 at 1:45 am

    Take a look to the documentation about Treeview and HierarchicalDataTemplate. Anyway I edit your example like this (XAML):

    <TreeView ItemsSource="{Binding CurrentClass}" >
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Students}">
                    <TextBlock Text="{Binding Year}" />
                    <HierarchicalDataTemplate.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding FirstName}"> </TextBlock>
                        </DataTemplate>
                    </HierarchicalDataTemplate.ItemTemplate>
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>
    

    and c#:

    public class ViewModel 
    {
        private List<FreshmenClass> currentClass;
    
        public ViewModel()
        {
            CurrentClass = new List<FreshmenClass>();
            FreshmenClass temp = new FreshmenClass();
            temp.Year = "2001";
            temp.Students.Add(new Student("Student1", "LastName1"));
            temp.Students.Add(new Student("Student2", "LastName2"));
    
            CurrentClass.Add(temp);
        }
    
        public List<FreshmenClass> CurrentClass
        {
            get { return currentClass; }
            set { currentClass = value; }
        }
    }
    

    the ItemsSource property is an IEnumerable.

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

Sidebar

Related Questions

I have been trying to make something like Facebook @tagged Friend name add in
I have been trying to make the sub-menu horizontal. In my HTML it looks
I have been trying to make this to be a little jQuery plugin that
I have been trying to make a StringTable class that holds a simple unordered_map<string,
I have been trying to make it so that when i right click a
I have been trying to make a layout for an Android app that functions
I have been trying to make a secure login for my site that I
I have been trying to make a cash register like code, where the user
I have been trying to make something work with JQuery. I have the following
I have been trying to make my website performs well. One way that may

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.