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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:09:05+00:00 2026-06-09T05:09:05+00:00

I am trying to implement a list that contains items of a certain type,

  • 0

I am trying to implement a list that contains items of a certain type, a Session. Each Session contains a list that contains the type Note. I want to display these Notes in the list under their respective Session header.

Currently I have tried two different methods. The first way was to use ItemsControls as ControlTemplate for the ListBoxItems. This is what I used in the picture below and it is how I want the list to look like. Each red rectangle shows a Session, the items below the header are the Notes. The problem then is that the selection from the ListBox selects ItemsControls instead of each separate Note.

The other way I tried to implement the list is to give each Note a property of which Session it belongs to in order to use a GroupStyle on the ListBox. If I then set the ItemsSource of the ListBox to a list of Notes instead of Sessions I’ll get a list that looks like the picture and that has selection of notes. The problem now is that I want the list to show Sessions that doesn’t contain any Notes as well.

Does anyone know what I should use to implement a list with selection and that works the way I have described?

  • 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-09T05:09:06+00:00Added an answer on June 9, 2026 at 5:09 am

    MainWindow.xaml:

        <TreeView ItemsSource="{Binding}">
            <TreeView.Resources>
                <HierarchicalDataTemplate DataType="{x:Type local:Session}" ItemsSource="{Binding Path=Notes}">
                    <TextBlock Text="{Binding Path=Name}" />
                </HierarchicalDataTemplate>
                <DataTemplate DataType="{x:Type local:Note}">
                    <Expander Header="{Binding Path=Notek}">
                        <TextBlock Foreground="Red" Text="{Binding Path=Details}" />
                    </Expander>
                </DataTemplate>
            </TreeView.Resources>
        </TreeView>
    

    MainWindow.xaml.cs

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            List<Session> sessions = new List<Session>();
            for (int i = 0; i < 5; i++)
            {
                List<Note> notes = new List<Note>();
                for (int j = i * 5; j < (i + 1) * 5; j++)
                {
                    Note note = new Note()
                    {
                        Notek = string.Format("Note {0}", j),
                        Details = string.Format("Note j = {0}{1}j*j = {2}", j, System.Environment.NewLine, j*j)
                    };
    
                    notes.Add(note);
                }
                Session session = new Session()
                {
                    Name = string.Format("Session # {0}", i),
                    Notes = notes
                };
                sessions.Add(session);
            }
            DataContext = sessions;
        }
    }
    
    public class Session
    {
        public string Name { get; set; }
        public List<Note> Notes { get; set; }
    }
    public class Note
    {
        public string Notek { get; set; }
        public string Details { get; set; }
    }
    

    I think that you can style your HierarchicalDataTemplate as you want. I just show you the example. I think its easier rather than ItemsControl with event handlers.

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

Sidebar

Related Questions

I am trying to implement an interface class, that contains a list of objects.
I'm trying to implement a list of items on a web page in which
I'm trying to implement a service contract that contains a method which takes a
i'm trying to implement a massive delete action to a list of items, where
I have a list that contains FrameworkElements and I want to create an extension
I'm trying to implement a mailing list system for my application. I'm currently using
I'm trying to implement my own List system in Java. the List class file
I'm trying to implement a linked list but get an error when compiling: intSLLst.cpp:38:
I'm trying to implement a link list which stores the city name (though you
I am trying to implement a to-do-list website to practice using Django. In models.py,

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.