Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > TreeView > Parent-Child relation in treeview

Not answered Parent-Child relation in treeview

Feed from this thread
  • Ivan avatar

    Posted on Jan 27, 2012 (permalink)

    This is a simplified version of my class

    public class Item
    {
    int _id;
     string _name;
    Item _parentItem;
    ObservableCollection<Item> _childItems;
    }

    The thing I want to do is to have them in a treeview acording to their relationship. And this is how I did it.

    <telerikNavigation:RadTreeView
       ItemsSource="{Binding TreeItems,Converter={StaticResource HierarchyConverter}}"
       ItemTemplate="{StaticResource TreeTemplate}"/>
     
    <converter:HierarchyConverter x:Name="HierarchyConverter"/>
    <telerik:HierarchicalDataTemplate
       x:Key="TreeTemplate"
        ItemsSource="{Binding Converter={StaticResource HierarchyConverter}}">
              <TextBlock Text="{Binding Name}"/>
    </telerik:HierarchicalDataTemplate>

    And I also use this converter

    public class HierarchyConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                // We are binding an item
                TreeItem item = value as TreeItem;
                if (item != null)
                {
                    return item.Children;
                }
     
                ObservableCollection<TreeItem> items = value as ObservableCollection<TreeItem>;
                if (items != null)
                {
                    return items;
                }
                return null;
            }
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                throw new NotImplementedException();
            }
        }

    I only get the first "level" and see the arrows next to the name but they won't expand so that I don't know if I did everything correct.

    Any help?

    Edit:

    Added this code

    <telerik:ContainerBindingCollection x:Key="TreeViewItemContainerBinding">
               <telerik:ContainerBinding PropertyName="IsExpanded" Binding="{Binding Path=IsActive, Mode=TwoWay}"/>
               <telerik:ContainerBinding PropertyName="IsSelected" Binding="{Binding Path=IsActive}"/>
           </telerik:ContainerBindingCollection>

    But now everything is expanded and when I click on an item it doesnt look like it's selected... it is just "flashing"



    Reply

  • Ivan avatar

    Posted on Jan 27, 2012 (permalink)

    Ignore the question...

    After I used the code (with the edited part) everything worked fine after I took care that the service which was providing me the data was called only once :)

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > TreeView > Parent-Child relation in treeview
Related resources for "Parent-Child relation in treeview"

Silverlight TreeView Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]