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

RadPanelBarItem Template Selector

3 Answers 185 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Joseph
Top achievements
Rank 1
Joseph asked on 03 Nov 2011, 11:50 PM

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

3 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 08 Nov 2011, 01:19 PM
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 >>

0
Tamar
Top achievements
Rank 1
answered on 05 May 2013, 02:55 PM
Hi,

I'm trying to bind the RadPanelBarItem Header to a string property in my ViewModel but it's not working and no binding error is shown.

Is there any problem binding the Header with a string object??

Here is my xaml:
<telerik:RadPanelBar ExpandMode="Multiple">
                               
                                <telerik:RadPanelBarItem IsExpanded="True" DropPosition="Inside" Header="{Binding PanelHeader, Mode=TwoWay}" Visibility="{Binding BottomPanel, Converter={StaticResource NullToVisibilityConverter}}"  Background="#FFAEBAC9" Foreground="White" Padding="3,3,3,3" BorderThickness="0,0,0,1" BorderBrush="#FFACACAC" ItemContainerStyle="{DynamicResource RadPanelBarItemStyle1}" FontSize="14.667">
                                    <ContentControl Content="{Binding BottomPanel, Mode=TwoWay}" />
                                </telerik:RadPanelBarItem>
</telerik:RadPanelBar>

Code:

public class ViewModel
{
public string PanelHeader = "My header";
}
0
Tina Stancheva
Telerik team
answered on 08 May 2013, 01:57 PM
Hi Tamar,

Can you please define a public getter on the PanelHeader property:
public class ViewModel
   {
       public string PanelHeader {get;set;}
   }
Then you should be able to properly bind the Header. If this doesn't help, you can send over your solution and we'll take a closer look at it.

Also, you can examine this tutorial describing how to populate RadPanelBar with business data.

Regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
PanelBar
Asked by
Joseph
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Tamar
Top achievements
Rank 1
Share this question
or