RadPanelBar, SL3, and Templates

6 posts, 0 answers
  1. Wayne
    Wayne avatar
    5 posts
    Member since:
    Oct 2007

    Posted 19 Jul 2010 Link to this post

    I'm attempting to use the RadPanelBar, but I cannot seem to make it work. first let me say I'm VERY new to Silverlight and XAML so most of the issues could very well be user error.

    I am able to get the XAML that gives me the header for each item in the list, but I am unable to get the header to expand and show the other data I want it to display. Second link shows how to do this with a bunch of work, custom control, etc...


    Is there a simple way to do this? I want to display very little info on the header from the object/class but display quite a bit more when it's expanded, and all the data comes from the same instance of the object.

    Any help would be greatly appreciated.
    Wayne


    I have a class, that I am adding many to the list and at run time I'm doing the following:

    radPanelBar.ItemsSource =

    items;

    and I have the following XAML for the RadPanelBar (most pulled from following two links)
    http://www.telerik.com/community/forums/silverlight/panelbar/how-to-set-radpanelbaritem-properties-when-data-binding.aspx
    http://www.telerik.com/community/forums/silverlight/panelbar/radpanelbar-itemstemplate-issue.aspx

     

     

     

    <Border CornerRadius="5" HorizontalAlignment="Center">

     

     

     

    <Border.Resources>

     

     

     

    <DataTemplate x:Key="RadPanelBarItemTemplate">

     

     

     

    <StackPanel Orientation="Horizontal" Margin="5">

     

     

     

    <TextBlock Text="{Binding SearchItem.OriginCity}" Width="75" />

     

     

     

    </StackPanel>

     

     

     

    </DataTemplate>

     

     

     

    </Border.Resources>

     

     

     

    <StackPanel Orientation="Horizontal" Margin="10">

     

     

     

    <Grid VerticalAlignment="Stretch">

     

     

     

    <telerikNavigation:RadPanelBar VerticalAlignment="Stretch" x:Name="radPanelBar" Width="250" Visibility="Visible">

     

     

     

    <telerikNavigation:RadPanelBar.ItemTemplate>

     

     

     

    <DataTemplate>

     

     

     

    <TextBlock Text="{Binding SearchItem.OriginCity}" Width="75" />

     

     

     

    </DataTemplate>

     

     

     

    </telerikNavigation:RadPanelBar.ItemTemplate>

     

     

     

    </telerikNavigation:RadPanelBar>

     

     

     

    </Grid>

     

     

     

    </StackPanel>

     

     

     

    </Border>

     

  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 22 Jul 2010 Link to this post

    Hello Wayne,

    In order to display additional info in the RadPanelBarItem in a databound RadPanelBar, it is best to use a HierarchicalDataTemplate. Therefore the ItemsSource collection of the RadPanelBar has to contain a hierarchical data, e.g collection that contain other collections.
    For example if the business object is defined like so:
    public class DataItem
    {
        public DataItem()
        {
            this.Details = new List<DataItem>();
        }
        public List<DataItem> Details { get; set; }
        public string Header { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
    }

    Then the following HierarchicalDataTemplate can be defined:
    <DataTemplate x:Key="PanelBarItemTemplate">
        <StackPanel>
            <TextBlock Text="{Binding Title}"/>
            <TextBlock Text="{Binding Description}"/>
        </StackPanel>
    </DataTemplate>
                 
    <telerik:HierarchicalDataTemplate x:Key="PanelBarHeaderTemplate"
                                      ItemsSource="{Binding Details}"
                                      ItemTemplate="{StaticResource PanelBarItemTemplate}">
        <TextBlock Text="{Binding Header}" Width="75" />
    </telerik:HierarchicalDataTemplate>

    And the definition of the RadPanelBar can be:
    <telerikNavigation:RadPanelBar VerticalAlignment="Stretch" x:Name="radPanelBar"
                              Width
    ="250"
                     ItemTemplate="{StaticResource PanelBarHeaderTemplate}">
    </telerikNavigation:RadPanelBar>

    I prepared a sample project illustrating this approach. Please take a look at it and let me know if it works for you or if you need more info.

    Best wishes,
    Tina Stancheva
    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. Wayne
    Wayne avatar
    5 posts
    Member since:
    Oct 2007

    Posted 22 Jul 2010 Link to this post

    As is normally the case, I got the code working after posting the question, but the work around I still thought was odd so I still wanted to see the response.

    Any chance in the future you can add an ItemSource to the HierarchicalDataTemplate, as at some point the last item in your hierarchy is going to be a single item without a bunch of children. (notice it’s Item not ItemS)


    Currently to use it, I had to create a List<class> items, then have my property read/write to list[0] in the getters and setters, this just LOOKS wrong in the code.

    Wayne
  5. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 23 Jul 2010 Link to this post

    Hello Wayne,

    We are keeping the code compatible with WPF and we will not be able to add new property to the HierarchicalDataTemplate that do not exist in WPF.

    Best wishes,
    Valentin.Stoychev
    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
  6. Wayne
    Wayne avatar
    5 posts
    Member since:
    Oct 2007

    Posted 23 Jul 2010 Link to this post

    Judging by your reply I’m going to guess that you don’t feel my request is completely un-logical or undoable, and given that the example I gave was at the end of most Hiarchies you’re dealing with a single object works both in Silver Light and WPF I have to ask: 

    To keep them compatible why not add the property to both code bases? This would give the functionality of the template being able to bind to a single object, and not force code to be written to implement a list when all you will ever have is a single item. 

    In short I wasn’t asking you to deviate from your path of making things compatible between WPF and Silver Light but rather suggesting you add functionality that would be useful, and if that means you need to add it to both, then add it to both. 

    So I ask again, what is the possibility of adding an ItemSource (not plural) property to the Hierarchical Data Template?

    Wayne

  7. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 23 Jul 2010 Link to this post

    Hello Wayne,

    I see your point.

    The problem is that in WPF we are using the HierarchyTemplate which is found in the framework and in SL we are using our own HierarchyDataTemplate (due to the lack of such template in SL2 and the limited template that exist in SL4).
     
    We can't modify the WPF Hierarchy template which comes from the framework.

    Sincerely yours,
    Valentin.Stoychev
    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
Back to Top
DevCraft banner