Bind PanelBar to a complex class

3 posts, 0 answers
  1. Guillaume
    Guillaume avatar
    39 posts
    Member since:
    Nov 2010

    Posted 13 Apr 2011 Link to this post

    Hello,

    I have created a class which is compilcated to bind to the PanelBar, so i need few advices from you.

    Here is my class :
    public class FlowTreeModel : INotifyPropertyChanged
       {
           public event PropertyChangedEventHandler PropertyChanged;
     
           private Organization _organization;
           private Dictionary<FolderType, DataItemTreeViewCollection> _items;
     
           public Organization Organization
           {
               get { return _organization; }
               set
               {
                   _organization = value;
                   OnPropertyChanged("Organization");
               }
           }
     
           public Dictionary<FolderType, DataItemTreeViewCollection> Items
           {
               get { return _items; }
               set
               {
                   _items = value;
                   OnPropertyChanged("Items");
               }
           }
     
           public FlowTreeModel()
           {
               Items = new Dictionary<FolderType, DataItemTreeViewCollection>();
           }
     
           /// <summary>
           /// Called when [property changed].
           /// </summary>
           /// <param name="propertyName">Name of the property.</param>
           public void OnPropertyChanged(string propertyName)
           {
               if (this.PropertyChanged != null)
               {
                   PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
               }
           }
       }

    In fact, I want each PanelBarItem has :
    - the header binded on Organization property
    - contains a TreeView where first parents nodes are each FolderType in Items property and childs of each parent node is the DataItemTreeViewCollection associate.

    Ex :

    - FolderType01
    ----DataItemTreeViewCollection01
    - FolderType02
    ----DataItemTreeViewCollection02

    I can set the header of each item by setting the ItemTemplate like this in RadPanelBar
    ItemTemplate="{StaticResource HeaderDataTemplate}"
    <DataTemplate x:Key="HeaderDataTemplate">
                <Grid>
                    <TextBlock Text="{Binding Organization.Name}" Margin="5,5,0,5"/>
                </Grid>
            </DataTemplate>
    But i can't set the content.

    DataItemTreeViewCollection class is a recursive class who works fine with  HierarchicalDataTemplate Do you understand, what i want ? Best regards, Guillaume
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 18 Apr 2011 Link to this post

    Hello Guillaume,

    The RadPanelBar inherits from RadTreeView and the best way in these situation is to use nested telerik:HierarchicalDataTemplates and nested ViewModels bound to them. You may also need to expose some properties to use for Binding like Folders for example. The Folders should retrieves the collection of FoldertTypes from the Dictionary Like so:
    private ObservableCollection<FolderType> folders;
           public ObservableCollection<FolderType> Folders
           {
               get
               {
                   return folders;
               }
               set
               {
                   this.folders = new ObservableCollection<FolderType>(Items.Keys);
                   OnPropertyChanged("Folders");
               }
           }
    For more info on how to use HierarchicaDataTemplates, pleasecheck out this article. Let us know if this helps you or not.

    Kind regards,
    Petar Mladenov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Guillaume
    Guillaume avatar
    39 posts
    Member since:
    Nov 2010

    Posted 28 Apr 2011 Link to this post

    Hello,

    Thanks for you advice. In fact, i have done with creating an ihnerit class of RadPanelBarItem and implementing my own UI logic (mix between bindings and controls manipulations).
    The result is well.

    Regards,
    Guillaume
Back to Top