SilverLight HeirarchicalDataTemplate

3 posts, 0 answers
  1. Sam
    Sam  avatar
    5 posts
    Member since:
    Jul 2012

    Posted 02 Jun 2012 Link to this post

    I am Having issues getting this to work in Silverlight. It works in WPF. How do you define  RadRibbonTab.ItemTemplate for silverlight? Please see the complte XAML below.

    I am following the 317172_RibbonViewPrism Code....

    Any help appreciated.

    <telerik:RadRibbonTab.ItemTemplate>
            <HierarchicalDataTemplate ItemsSource="{Binding Items}" ItemTemplateSelector="{StaticResource ItemTemplateSelector}">
                <TextBlock Text="{Binding Header}" />
            </HierarchicalDataTemplate>
        </telerik:RadRibbonTab.ItemTemplate>


    <telerik:RadRibbonTab x:Class="Module1.Views.Module1View"
                          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                          xmlns:local="clr-namespace:Module1"
                          xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                          xmlns:vm="clr-namespace:Module1.ViewModels"
                          Header="{Binding Header}"
                          IsSelected="{Binding IsSelected,Mode=TwoWay}"
                          ItemsSource="{Binding Groups}">
        <telerik:RadRibbonTab.DataContext>
            <vm:Module1VM />
        </telerik:RadRibbonTab.DataContext>
        <telerik:RadRibbonTab.Resources>
            <DataTemplate x:Key="ButtonTemplate">
                <telerik:RadRibbonButton Command="{Binding MyCommand}"
                                         Foreground="Red"
                                         Text="{Binding Text}" />
            </DataTemplate>
            <DataTemplate x:Key="SplitButtonTemplate">
                <telerik:RadRibbonSplitButton Command="{Binding MyCommand}"
                                              DropDownContent="{Binding}"
                                              Foreground="Blue"
                                              Text="{Binding Text}">
                    <telerik:RadRibbonSplitButton.DropDownContentTemplate>
                        <DataTemplate>
                            <ListBox ItemsSource="{Binding Children}">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Text}" />
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                        </DataTemplate>
                    </telerik:RadRibbonSplitButton.DropDownContentTemplate>
                </telerik:RadRibbonSplitButton>
            </DataTemplate>
     
            <local:TemplateSelector x:Key="ItemTemplateSelector"
                                    ButtonTemplate="{StaticResource ButtonTemplate}"
                                    SplitButtonTemplate="{StaticResource SplitButtonTemplate}" />
        </telerik:RadRibbonTab.Resources>
        <telerik:RadRibbonTab.ItemTemplate>
            <HierarchicalDataTemplate ItemsSource="{Binding Items}" ItemTemplateSelector="{StaticResource ItemTemplateSelector}">
                <TextBlock Text="{Binding Header}" />
            </HierarchicalDataTemplate>
        </telerik:RadRibbonTab.ItemTemplate>
    </telerik:RadRibbonTab>
  2. Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 06 Jun 2012 Link to this post

    Hi Sanjeev Rangaiah,

     I'm not sure why do you need HierarchicalTemplate for the RadRibbonTab. The Tab control and the RibbonTabs in particular doesn't support  HierarchicalTemplates and they do not need it. it is not a hierarchical control. You have two types of templates that define the look of the tab - HeaderTempalte and the ItemTemplate. So I guess that you need to set the HeaderTemplate displaying you Header property and the ItemTemplate - just set the ItemTemplateSelector to be you TemplateSelector.
    Please let me know if this works for  you.

    Greetings,
    Miro Miroslavov
    the Telerik team

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

  3. DevCraft banner
  4. Sam
    Sam  avatar
    5 posts
    Member since:
    Jul 2012

    Posted 06 Jun 2012 Link to this post

    Thanks Miro,

    I get your point. However the above piece of code worked in silverlight too!  The difference between WPF and Silverlight was that in Silverlight We need to inherit TemplateSelector from Telerik.Windows.Controls.DataTemplateSelector.

    In WPF, TemplateSelector is inherited from  Systems.Windows.Controls.DataTemplateSelector.

    I was using "Project Linking" between the WPF and silverlight project and hence this would not work. I removed the project link for this TemplateSelector class file and created a new TemplateSelector class file for silverlight  and inherited from Telerik.Windows.Controls.DataTemplateSelector.

    Everything works as expected.

Back to Top