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

Tab Icon binding at run time

1 Answer 53 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Bhavin asked on 08 Oct 2009, 08:08 PM
 <Style x:Key="RadTabControlStyle">
                <Setter Property="telerikNavigation:RadTabControl.ItemContainerStyle">
                        <Style TargetType="telerikNavigation:RadTabItem">
                            <Setter Property="FontFamily" Value="Tahoma"/>
                            <Setter Property="Foreground" Value="White"/>
                            <!--Setting the template for the headers.-->
                            <Setter Property="HeaderTemplate">
                                        <WrapPanel Margin="3">
                                            <Image Source="{Binding}" Height="25" />
                                            <TextBlock Text="{Binding}" FontSize="15" TextAlignment="Center"   VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="110" >
                                <Trigger Property="IsSelected" Value="False">
                                    <Setter Property="BorderThickness" Value="0.5" />
                                    <Setter Property="BorderBrush" Value="LightGray" />

This is the style I am applying to radTabcontrol and Binding tabItem in xaml
<telerikNavigation:RadTabItem x:Name="tbAddress" Header="Address" Foreground="Black" TabIndex="2"   HorizontalAlignment="Left">
                                <ctrl:AddressControl x:Name="ctrlAddress"  ></ctrl:AddressControl>

I am not assigning any ItemSource to tabControl,It works great it show header text with centerd align.
But problem is that I want to bind different image with this header text in tabHeader and I have mentined Image sOurce={Binding} so that I can provide image at run time

DataTemplate template = tbIdentification.HeaderTemplate as DataTemplate;
            if (template == null) return;
            WrapPanel pnl = template.LoadContent() as WrapPanel;
Image ImgButton = pnl.Children[0] as Image;
ImgButton.Source = (ImageSource)new ImageSourceConverter().ConvertFrom(new Uri("pack://application:,,,/SafetyAuditUserControl;component/Images/truck.png",UriKind.RelativeOrAbsolute ));

It not showing Image.Please help me out for this ASAP.

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 13 Oct 2009, 10:41 AM
Hello bhavin patel,

I am sorry for the dealyed reply.

You can use a ValueConverter for your binding that will choose the appropriate image.

A value converter can be any class that implements the IValueConverter interface. It receives the value of the binding (in your case the header) and returns the new value, you will need to return an ImageSource.

Here are some blog posts that describe value converters in greater detail:

All the best,
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question