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

Tab Icon binding at run time

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


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>
                            </telerikNavigation:RadTabItem>

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.BeginInit();
ImgButton.Source = (ImageSource)new ImageSourceConverter().ConvertFrom(new Uri("pack://application:,,,/SafetyAuditUserControl;component/Images/truck.png",UriKind.RelativeOrAbsolute ));
            ImgButton.EndInit();


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

1 Answer, 1 is accepted

Sort by
0
Miroslav
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:

http://blogs.msdn.com/bencon/archive/2006/05/10/594886.aspx
http://blogs.msdn.com/delay/archive/2008/05/04/ivalueconverter-the-swiss-army-knife-of-bindings-propertyviewer-sample-is-a-wpf-silverlight-visualization-and-debugging-aid.aspx

All the best,
Miroslav
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.
Tags
TabControl
Asked by
Bhavin
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
Share this question
or