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

Tab Icon

1 Answer 198 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
Garry
Top achievements
Rank 1
Garry asked on 06 Jul 2009, 08:17 PM
I can not seem to figure out how to add an icon to the RadTabItem.Header. To tell you the truth I couldn't figure out hwo to add one to the Standard windows TabControl either ;). I can easily do it in XAML, but I need to do it in the code behind for some dynamically created tabs.

Any pointer?

Thanks!

1 Answer, 1 is accepted

Sort by
0
Miroslav
Telerik team
answered on 07 Jul 2009, 07:21 AM
Hello Garry,

You can achieve this in several ways:

1. Create the visual elements in code and assign them to the Header, something like:

var panel = new Grid();
panel.Children.Add(new TextBox(){ Text = "Some Text"});

This is somthing that I will not recommend because it is hard to maintain.

2. Create the Header from a string using XamlReader.Load method. You need to pass it a valid Xaml as a string and it will return the object corresponding to the Xaml. Please note that you will need to include all the necessary namespaces as in the root xaml element as well. Again this approach is not very maintainable.

3. Add a HeaderTemplate to the item and then set a ViewModel class. Then you can bind an Image control in the template to a property in your class. If it is observable, you will be able to easily change the icon and other content.

If you are not binding the ItemsSource of the TabControl (and you are creating the TabItems in code) you can easily get hold of a DataTemplate by adding it to the resources of a UserControl and then getting it from there like so:

var headerTremplate = someControl.Resources["myTemplateKey"] as DataTemplate;

this way the template will remain in Xaml and will be more maintainable. (and you may be able to edit in Blend).

Hopefully this will help you decide what is best in your case.

Best wishes,
Miroslav
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.
Tags
TabControl
Asked by
Garry
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
Share this question
or