ItemTemplateSelector example needed

3 posts, 1 answers
  1. bluewater
    bluewater avatar
    24 posts
    Member since:
    Jan 2007

    Posted 11 Feb 2012 Link to this post

    Hi telerik,

    I am working on my first Breadcrumb. It binds  (on Level 1) to a flat ObservableCollection, on the following levels on a hierarchical/self-referencing entity set. I am therefore trying to use the ItemTemplateSelector property but it seems the TemplateSelector's SelectTemplate() method never gets called.

    1. I got the same thing working OK with a RadTreeView.
    2. If I define a HierarchicalDataTemplate within the breadcrumb directly, the binding works but only for Level 1 and 2, i.e. the self-referencing part is missing - unsurprisingly, as the template is designed for level 1/2 only.

    Would you have any example how to use TemplateSelector with RadBreadCrumb? 
    Your help most appreciated, thx,
    bluewater

    My breadcrumb:
    <telerik:RadBreadcrumb Name="Breadcrumb" Grid.Column="1" Grid.Row="3" 
                           ItemsSource="{Binding Serviceclasses}"
                           ItemTemplateSelector="{StaticResource myDataTemplateSelector}"                                   
                           >

    My Selector XAML:
    <UserControl.Resources>
     
        <telerik:HierarchicalDataTemplate x:Key="ChildServicegroupsTemplate"
                                          ItemsSource="{Binding Path=ChildServicegroups}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Sortkey}" Margin="0,0,10,0"  />
                <TextBlock Text="{Binding Code}" FontWeight="Bold" />
                <TextBlock Text="{Binding Name}" Margin="10,0,0,0" />
            </StackPanel>
        </telerik:HierarchicalDataTemplate>
     
        <telerik:HierarchicalDataTemplate x:Key="ServicegroupsTemplate"
                                          ItemsSource="{Binding Path=ChildServicegroups}"
                                          ItemTemplate="{StaticResource ChildServicegroupsTemplate}" >
     
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Sortkey}" Margin="0,0,10,0"  />
                <TextBlock Text="{Binding Code}" FontWeight="Bold" Foreground="Blue" FontSize="12"  />
                <TextBlock Text="{Binding Name}" Margin="10,0,0,0" Foreground="Blue" FontSize="12" />
            </StackPanel>
        </telerik:HierarchicalDataTemplate>
     
        <telerik:HierarchicalDataTemplate  x:Key="ServiceclassTemplate" 
            ItemTemplate="{StaticResource ServicegroupsTemplate}" 
            ItemsSource="{Binding Servicegroups}" >
     
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Name}" Foreground="Green" FontSize="24"  />
            </StackPanel>
        </telerik:HierarchicalDataTemplate>
         
        <itsf:ServicegroupsTemplateSelector x:Key="myDataTemplateSelector" 
            ServiceclassTemplate="{StaticResource ServiceclassTemplate}"  
            ServicegroopRootTemplate="{StaticResource ServicegroupsTemplate}"
            ServicegroupChildTemplate="{StaticResource ChildServicegroupsTemplate}"/>
     
    </UserControl.Resources>

    My template selector is basically right from your league/division/team example, with the required mods

  2. Answer
    Zarko
    Admin
    Zarko avatar
    755 posts

    Posted 15 Feb 2012 Link to this post

    Hi,
    Thank you for the feedback. We are aware of the problem with the ItemTemplateSelector and you can track the problem on this issue here. Meanwhile, there are two possible workarounds:
    - if you want to use the ItemTemplateSelector you'll have to edit the default template of the RadBreadcrumb (it's about 1000 lines of XAML)
    - instead of an ItemTemplateSelector you can use a ItemContainerStyleSelector and select a style with HeaderTemplate setter for each individual item.
    I've attached two project that show this workarounds so could you please examine it and if you have more questions feel free to ask. 

    Regards,
    Zarko
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
  4. bluewater
    bluewater avatar
    24 posts
    Member since:
    Jan 2007

    Posted 17 Feb 2012 Link to this post

    thank you Zarko. I appreciate your support.
Back to Top