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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:29:03+00:00 2026-06-04T08:29:03+00:00

I need to use an ObservableCollection and only one class. Here is my code.

  • 0

I need to use an ObservableCollection and only one class. Here is my code. For some reason I cannot get the TreeView to populate with the Observable Collection . Any help would be appreciated.

XAML:

<UserControl x:Class="ValidationWPF.ValidationUserControl"
             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:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:local="clr-namespace:ValidationWPF.DataSources"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <local:ValidationItem x:Key="ValidationMessages" />

        <DataTemplate x:Key="Messages">
            <TextBlock Text="{Binding Messages}" />
        </DataTemplate>

        <HierarchicalDataTemplate x:Key="SubItem" ItemTemplate="{StaticResource Messages}" ItemsSource="{Binding Messages}" >
            <TextBlock Text="{Binding subItem}" />
        </HierarchicalDataTemplate>

        <HierarchicalDataTemplate  ItemTemplate="{StaticResource SubItem}" x:Key="ItemTemplate"
                ItemsSource="{Binding subItem}">
            <TextBlock Text="{Binding item}" FontWeight="Bold" />
        </HierarchicalDataTemplate>

    </UserControl.Resources>

    <Grid>
        <telerik:RadTreeView ItemsSource="{Binding Source={StaticResource ValidationMessages}}"
                ItemTemplate="{StaticResource ItemTemplate}" x:Name="RadTreeView"/> 
    </Grid>
</UserControl>

CLASS:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace ValidationWPF.DataSources
{
    class ValidationItem : ObservableCollection<ValidationItem>
    {
        public ValidationItem()
        {
        }

        public ValidationItem(Item item, SubItem subItem, string Messages)
        {
            this.item = item;
            this.subItem = subItem;
            this.Message = Messages;
        }

        public string Message { get; set; }

        public SubItem subItem { get; set; }

        public Item item { get; set; }

        public ObservableCollection<ValidationItem> ValidationItems
        {
            get
            {
                Add(new ValidationItem(Item.Customer, SubItem.Name, "Customer Name Cannot be Null"));
                Add(new ValidationItem(Item.Customer, SubItem.Phone, "Phone number cannot be Null"));
                Add(new ValidationItem(Item.Customer, SubItem.Phone, "Phone number must be in the format (###)###-####"));
                Add(new ValidationItem(Item.Customer, SubItem.Address, "Customer Address cannot be Null"));
                return ValidationItems;
            }
        }
    }

    public enum Item
    {
        Customer
    }

    public enum SubItem
    {
        Address,
        Phone,
        Name
    }
}
  • 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-04T08:29:06+00:00Added an answer on June 4, 2026 at 8:29 am

    UPDATE: OK, lots going on here, so took a while to really understand. Two things.

    Change the default constructor of you model to

    public ValidationItem()
        {
            Add(new ValidationItem(Item.Customer, SubItem.Name, "Customer Name Cannot be Null"));
            Add(new ValidationItem(Item.Customer, SubItem.Phone, "Phone number cannot be Null"));
            Add(new ValidationItem(Item.Customer, SubItem.Phone, "Phone number must be in the format (###)###-####"));
            Add(new ValidationItem(Item.Customer, SubItem.Address, "Customer Address cannot be Null"));
        }
    

    The other is to change your “subItem” property. the HierarchicalDataTemplate expects the ItemsSource to be an IEnumerable. So change the property to be

    public IEnumerable<SubItem> subItems
    

    Even if you only have one, make it an IEnumerable. You will also need to change your HierarchicalDataTemplates to

        <HierarchicalDataTemplate x:Key="SubItem">
            <TextBlock Text="{Binding}" />
        </HierarchicalDataTemplate>
    
        <HierarchicalDataTemplate ItemTemplate="{StaticResource SubItem}" x:Key="ItemTemplate"
                ItemsSource="{Binding subItems}">
            <TextBlock Text="{Binding item}" FontWeight="Bold" />
        </HierarchicalDataTemplate>
    

    It also helps to debug your application and view the Output window. If there are any binding problems it will tell you. Something like “Error binding, could not find property ‘Messages'”.

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

Sidebar

Related Questions

I need to use scp update some directory at another server. It is similar
I need to use some classes inside the app_code folder of a website project
I'm using Microsoft Activity Library Designer; For some reasons I need to use ListBox
I have an ObservableCollection<T> in one of my projects and I need to make
So, I need use this event so I can navigate trought blog posts. I
Need to use own imaged markers instead built-in pins. I have several questions. 1.
i need to use the animate property for a less than usual activity. i
I need to use something like get_or_create() but the problem is that I have
I need to use Twitter api from iPhone 3.0 (SDK 3.0). can i use
I need to use system-specific functions, e.g. ftello() (defined in stdio.h as per POSIX

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.