Tab Icon binding at run time

2 posts, 0 answers
  1. bhavin patel
    bhavin patel avatar
    24 posts
    Member since:
    Jun 2005

    Posted 08 Oct 2009 Link to this post

     <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.
  2. Miroslav
    Miroslav avatar
    922 posts

    Posted 13 Oct 2009 Link to this post

    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.
  3. DevCraft R3 2016 release webinar banner
Back to Top