Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing HierarchicalDataTemplate and Observable in WPF
    primarykey
    data
    text
    <p>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. </p> <p>XAML:</p> <pre><code>&lt;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"&gt; &lt;UserControl.Resources&gt; &lt;local:ValidationItem x:Key="ValidationMessages" /&gt; &lt;DataTemplate x:Key="Messages"&gt; &lt;TextBlock Text="{Binding Messages}" /&gt; &lt;/DataTemplate&gt; &lt;HierarchicalDataTemplate x:Key="SubItem" ItemTemplate="{StaticResource Messages}" ItemsSource="{Binding Messages}" &gt; &lt;TextBlock Text="{Binding subItem}" /&gt; &lt;/HierarchicalDataTemplate&gt; &lt;HierarchicalDataTemplate ItemTemplate="{StaticResource SubItem}" x:Key="ItemTemplate" ItemsSource="{Binding subItem}"&gt; &lt;TextBlock Text="{Binding item}" FontWeight="Bold" /&gt; &lt;/HierarchicalDataTemplate&gt; &lt;/UserControl.Resources&gt; &lt;Grid&gt; &lt;telerik:RadTreeView ItemsSource="{Binding Source={StaticResource ValidationMessages}}" ItemTemplate="{StaticResource ItemTemplate}" x:Name="RadTreeView"/&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>CLASS:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections.ObjectModel; namespace ValidationWPF.DataSources { class ValidationItem : ObservableCollection&lt;ValidationItem&gt; { 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&lt;ValidationItem&gt; 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 } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload