This is a migrated thread and some comments may be shown as answers.

Help On using RadPanelBar with DataTemple and Hiarchial DataTemplate

1 Answer 78 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Nivid
Top achievements
Rank 1
Nivid asked on 21 Dec 2011, 04:40 PM
I am using Hiearchial DataTemplates with normal DataTemplate that i saw in one of the forums in here. But i have a problem when the items are displayed properly but it is not expanded when clicked on the items. here is the code that i am using to Display two items at present.
The Link that i saw  this way to display can be found here

XAML:

 

 

 

 

 

<Window.Resources>
        <DataTemplate x:Key="PanelBarItemTemplate">
            <StackPanel Orientation="Vertical">
                <TextBlock Text="{Binding PropertyName}"/>
                <TextBlock Text="{Binding PropertyValue}"/>
                <TextBlock Text="{Binding Comments}"/>
            </StackPanel>
        </DataTemplate>
  
        <HierarchicalDataTemplate x:Key="PanelBarHeaderTemplate"
                           ItemsSource="{Binding Items,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                           ItemTemplate="{StaticResource PanelBarItemTemplate}">
            <TextBlock Text="{Binding Title}" />
        </HierarchicalDataTemplate>
  
    </Window.Resources>
  
    <Grid>
        <DockPanel>
            <DockPanel DockPanel.Dock="Right" Width="350">
                <Label />
            </DockPanel>
            <DockPanel DockPanel.Dock="Right" VerticalAlignment="Bottom">
                <telerik:RadPanelBar ItemsSource="{Binding AccordionItems,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" 
                    ItemTemplate="{StaticResource PanelBarHeaderTemplate}" telerik:StyleManager.Theme="Windows7"/>
            </DockPanel>
        </DockPanel>
    </Grid>

C# ViewModel
public class MainViewModel:ViewModelBase
   {
       public MainViewModel()
       {
           _accordionItems = new List<AccoordionHelper>();
           AccordionItems = new List<AccoordionHelper>();
           _accordionItems.Add(new AccoordionHelper("OffFinalBill", new AccordionItemsHelper(){ Comments="hello", PropertyName="Off Final 1: ", PropertyValue= "12121" }));
           _accordionItems.Add(new AccoordionHelper("PartFinal", new AccordionItemsHelper() { Comments = "hello", PropertyName = "Off Final 1: ", PropertyValue = "12121" }));
           AccordionItems = _accordionItems;
       }
       private List<AccoordionHelper> _accordionItems = new List<AccoordionHelper>();
       public List<AccoordionHelper> AccordionItems
       {
           get
           {
               if (_accordionItems == null)
               {
                   _accordionItems = new List<AccoordionHelper>();
               }
               return _accordionItems;
           }
           set
           {
               _accordionItems = value;
               this.RaisePropertyChanged("AccordionItems");
           }
       }
       
        
   }
   public class AccoordionHelper:ViewModelBase
   {
       private string _title;
       public string Title
       {
           get
           {
               return _title;
           }
           set
           {
               _title = value;
               this.RaisePropertyChanged("Title");
           }
       }
       private AccordionItemsHelper _items;
       public AccordionItemsHelper Items
       {
           get
           {
               if (_items == null)
               {
                   _items = new AccordionItemsHelper();
               }
               return _items;
           }
           set
           {
               _items = value;
               this.RaisePropertyChanged("Items");
           }
       }
       public AccoordionHelper( string title, AccordionItemsHelper items)
       {
           Items=items;
           Title = title;
       }
   }
   public class AccordionItemsHelper
   {
       public string PropertyName { get; set; }
       public string PropertyValue { get; set; }
       public string Comments { get; set; }
   }

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 26 Dec 2011, 02:53 PM
Hello,

 The RadPanelBar inherits from RadTreeView and they are both HierarChical controls. They are ItemControls - they are consisted of Items and their containers : RadPanelBarItems (or RadTreeViewItems) have Items property too. So when you bind your first level's ItemsSource collection:

<HierarchicalDataTemplate x:Key="PanelBarHeaderTemplate"
                   ItemsSource="{Binding Items,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                   ItemTemplate="{StaticResource PanelBarItemTemplate}">
    <TextBlock Text="{Binding Title}" />
</HierarchicalDataTemplate>
the RadPanelBar expects collection of objects but you provide a single object:
public class AccoordionHelper:ViewModelBase
   {
       private string _title;
       public string Title
       {
           get
           {
               return _title;
           }
           set
           {
               _title = value;
               this.RaisePropertyChanged("Title");
           }
       }
       private AccordionItemsHelper _items;
       public AccordionItemsHelper Items
       {
           get
 Making this Items property a List of AccordionItemsHelper s will solve your scenario as it is done in the attached project. Feel free to ask if you need further assistance.

Greetings,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
PanelBar
Asked by
Nivid
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or