Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > PanelBar > RadPanelBarItem Template Selector

Not answered RadPanelBarItem Template Selector

Feed from this thread
  • Joseph avatar

    Posted on Nov 3, 2011 (permalink)

    I have a template selector that I would like to work with the RadPanelBarItem items presenter. Unfortunatley the template is never called. I am doing the following:

    <telerik:RadPanelBar Grid.Row="1" x:Name="PART_RAD_PANEL_BAR" Margin="5,5,0,0" ItemsSource="{Binding UpdateSourceTrigger=PropertyChanged, Path=ExperimentCollection.ExperimentTriggerCollection, NotifyOnSourceUpdated=True}" >             
    </telerik:RadPanelBar>

    And am using the following Style for the RadPanelBarItem (Cut for brevity)

    <Style x:Key="PanelBarItemKey" TargetType="{x:Type telerik:RadPanelBarItem}">
        <Setter Property="Background">
            <Setter.Value>
                <LinearGradientBrush EndPoint="0.5,1"
                                     StartPoint="0.5,0">
                    <GradientStop Color="White" />
                    <GradientStop Color="Gainsboro"
                                  Offset="0.43" />
                    <GradientStop Color="#FFADADAD"
                                  Offset="0.44" />
                    <GradientStop Color="#FFD4D4D4"
                                  Offset="1" />
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="BorderBrush"
                Value="#FF848484" />
        <Setter Property="BorderThickness"
                Value="1" />
        <Setter Property="Foreground"
                Value="Black" />
        <Setter Property="Padding"
                Value="3" />
        <Setter Property="HorizontalContentAlignment"
                Value="Stretch" />
        <Setter Property="VerticalContentAlignment"
                Value="Stretch" />
        <Setter Property="HeaderTemplate"
                Value="{StaticResource PanelBarItemTemplate}" />
        <Setter Property="ItemsSource"
                Value="{Binding SelectedTrigger}" />
        <Setter Property="ItemTemplateSelector"
                Value="{StaticResource TriggerTemplateSelectorKey}" />
        <Setter Property="ChildItemsTemplate">


    And the following Template Selector:

    Public Class TriggerTemplateSelector
        Inherits DataTemplateSelector
     
        Public Overrides Function SelectTemplate(ByVal item As Object, ByVal container As DependencyObject) As DataTemplate
     
            If item IsNot Nothing Then
     
                Dim et As ExperimentTrigger = CType(item, ExperimentTrigger)
     
                Dim element As FrameworkElement
                element = TryCast(container, FrameworkElement)
     
                Select Case et.TriggerType
                    Case "Timer"
                        Return TryCast(element.FindResource("TimerTriggerTemplate"), DataTemplate)
                    Case "Damage"
                        Return TryCast(element.FindResource("TriggerDamageTemplate"), DataTemplate)
                    Case "IED Detonation"
                        Return TryCast(element.FindResource("TriggerDetonationTemplate"), DataTemplate)
                End Select
     
            Else
                Return Nothing
            End If
     
            Return Nothing
     
        End Function
    End Class

    The Items in the RadPanelBarItems need to call the template selector which I thought would be called by setting the ItemTemplateSelector in the Style, but this does not seem to be the case. How can I call my template selector in the RadPanelBarItem Style?

    I am using the following to link to further illustrate.

    If I do the following in XAML the template selector is called but I don't know how many RadPabelBarItems I will have:

    <telerik:RadPanelBar Grid.Row="1"
                         Margin="5,5,0,0"
                         >
     
        <telerik:RadPanelBarItem Header="Test"
                                 Style="{x:Null}"
                                 ItemTemplateSelector="{StaticResource TriggerTemplateSelectorKey}"
                                 ItemsSource="{Binding UpdateSourceTrigger=PropertyChanged, Path=ExperimentCollection.ExperimentTriggerCollection, NotifyOnSourceUpdated=True}" />
    </telerik:RadPanelBar>


    I have not had any luck with this so I am currently trying to do it procedurally. Is this possible to do this in XAML?

    Regards,
    Joseph

    Reply

  • Tina Stancheva Tina Stancheva admin's avatar

    Posted on Nov 8, 2011 (permalink)

    Hi Joseph,

    Since you're binding the RadPanelBar ItemsSource collection ans you need to call the ItemTemplateSelector for each RadPanelBarItem you can set the ItemTemplateSelector property in the RadPanelBar definition. Basically when you set it in the RadPanelBarItemStyle it will be called for the children Items collection of each item but not for the root items and since there is no ItemTemplate defined for the root items - the control won't know that they ave children and won't look for their ItemTemplate.

    Please try this:
    <telerik:RadPanelBar Grid.Row="1"
    x:Name="PART_RAD_PANEL_BAR" Margin="5,5,0,0"
    ItemsSource="{Binding UpdateSourceTrigger=PropertyChanged, Path=ExperimentCollection.ExperimentTriggerCollection, NotifyOnSourceUpdated=True}"
    ItemTemplateSelector="{StaticResource TriggerTemplateSelectorKey}">            
    </telerik:RadPanelBar>
    and let us know if it works for you.

    All the best,
    Tina Stancheva
    the Telerik team

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

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > PanelBar > RadPanelBarItem Template Selector
Related resources for "RadPanelBarItem Template Selector"

WPF PanelBar Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]