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

Conditional formatting of RadPanelBar items

8 Answers 205 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 09 Jul 2009, 09:03 AM
Hi

My RadPanelBar is bound to a collection of objects like this:

XAML:
<HierarchicalDataTemplate x:Key="hdt" ItemsSource="{Binding ClientPublications}">                         
            <TextBlock Text="{Binding Name}"></TextBlock> 
</HierarchicalDataTemplate> 
 
<telerik:RadPanelBar x:Name="reportMenuPanelBar" Grid.Row="1" Margin="1,0,1,1" ItemsSource="{Binding}" ItemTemplate="{StaticResource hdt}" Selected="reportMenuPanelBar_Selected"
</telerik:RadPanelBar> 

C#:
IList<ClientReport> reports = mgr.GetAllClientReports(); 
reportMenuPanelBar.DataContext = reports; 

I want the textweight for the child panel bar items to be different (i.e. bold or normal) depending on the value of an object's property.

How can I do this?

Thanks.

8 Answers, 1 is accepted

Sort by
0
Tihomir Petkov
Telerik team
answered on 09 Jul 2009, 10:51 AM
Hello Ryan,

You can use a TemplateSelector in your scenario. Please take a look at the attached sample project. The sample is using a RadTreeView control but the usage of a TemplateSelector is identical with a RadPanelBar control.

Greetings,
Tihomir Petkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Ryan
Top achievements
Rank 1
answered on 10 Jul 2009, 01:33 PM
Thanks Tihomir, but unfortunately I cannot open the TreeView_TemplateSelector project. It is not supported by my version of VS.

I using VS 2008 no SP.

Regards
Ryan
0
Accepted
Tihomir Petkov
Telerik team
answered on 13 Jul 2009, 12:46 PM
Hi Ryan,

Is there any specific reason why you are not using the SP for Visual Studio 2008? It is generally desireable to use the latest updates and service packs because of all the bug fixes and support for the latest dev tools.

In case you don't want to upgrade your installation of Visual Studio, you can refer to the following blog post which discusses data binding in WPF and has a section demonstrating how to use TemplateSelectors:

http://blogs.telerik.com/deyanvarchev/posts/08-06-17/wpf_data_binding_unraveling_data_templates.aspx

Let me know if the article helps.

All the best,
Tihomir Petkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Ryan
Top achievements
Rank 1
answered on 14 Jul 2009, 08:33 AM
Hi Tihomir

I am in fact using SP1 (I was told otherwise, but never mind).

I am using VS2008 Pro 9.0.30729.1

I still can't open the project.
0
Tihomir Petkov
Telerik team
answered on 14 Jul 2009, 01:59 PM
Hello Ryan,

You probably do not have the requirements for Silverlight development installed on your machine (runtime, SDK, tools for VS). Did you read the article I refered to in my last post? It explains how to use TemplateSelectors in WPF. If you read the article there will be no need to check the sample Silverlight project I sent originally.

Sincerely yours,
Tihomir Petkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Ryan
Top achievements
Rank 1
answered on 22 Jul 2009, 01:13 PM
Hi Tihomir

Thank you for the information you have provided so far. It has helped.

However it is not working quite right for me, probably because I have not implemented properly.
The datasource is a collection of Report objects andeEach Report object may contain a collection of Publication objects.



There are no RadPanelBarItems (Publications) showing. Only RadPanelBar's (Reports) are showing.

What am I doing wrong?

XAML:
<Style x:Key="UnreadItemStyle" TargetType="TextBlock"
            <Setter Property="FontWeight" Value="Bold" ></Setter
        </Style> 
        <Style x:Key="ReadItemStyle" TargetType="TextBlock"
            <Setter Property="FontWeight" Value="Normal"></Setter> 
</Style>         
         
<HierarchicalDataTemplate x:Key="unreadPublications" ItemsSource="{Binding ClientPublications}">             
            <TextBlock Text="{Binding Name}" Style="{StaticResource UnreadItemStyle}"></TextBlock> 
</HierarchicalDataTemplate> 
<HierarchicalDataTemplate x:Key="readPublications" ItemsSource="{Binding ClientPublications}"
            <TextBlock Text="{Binding Name}" Style="{StaticResource ReadItemStyle}"></TextBlock> 
</HierarchicalDataTemplate> 
<local:CustomDataTemplateSelector x:Key="customSelector"></local:CustomDataTemplateSelector> 
 
<telerik:RadPanelBar x:Name="reportMenuPanelBar" Grid.Row="1" Margin="1,0,1,1"  
                                ItemTemplateSelector="{StaticResource customSelector}" 
                                ItemsSource="{Binding}" 
                                Selected="reportMenuPanelBar_Selected"
            </telerik:RadPanelBar> 

CustomDataTemplateSelector:
public class CustomDataTemplateSelector : DataTemplateSelector 
    { 
        public override DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container) 
        { 
            var reports = item as ClientReport; 
            IList<ClientPublication> pubs = reports.ClientPublications; 
            ContentPresenter presenter = container as ContentPresenter; 
            if (presenter != null && pubs != null
            {    
                foreach (var pub in pubs) 
                { 
                    if (pub != null && pub.HasBeenRead == true
                    { 
                        return presenter.TryFindResource("readPublications"as DataTemplate; 
                    } 
                    else 
                    { 
                        return presenter.TryFindResource("unreadPublications"as DataTemplate; 
                    } 
                }                 
            } 
 
            return base.SelectTemplate(item, container); 
        } 
 
    } 

XMAL.CS:

IList<ClientReport> reports = mgr.GetAvailableClientReports();                         
reportMenuPanelBar.DataContext = reports;  


0
Accepted
Tihomir Petkov
Telerik team
answered on 22 Jul 2009, 04:20 PM
Hi Ryan,

Your mistake was that in the TemplateSelector you were assuming the item would always be a ClientReport, so when it was the turn of ClientPublications to get their templates they were not getting any.

I prepared an example that demonstrates how to get the selector to work in your scenario. Please take a look and let me know if my solution works for you.

Sincerely yours,
Tihomir Petkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Ryan
Top achievements
Rank 1
answered on 23 Jul 2009, 08:57 AM
Thanks for your help Tihomir!
Tags
PanelBar
Asked by
Ryan
Top achievements
Rank 1
Answers by
Tihomir Petkov
Telerik team
Ryan
Top achievements
Rank 1
Share this question
or