Tab Icon

2 posts, 0 answers
  1. Garry
    Garry avatar
    205 posts
    Member since:
    Nov 2010

    Posted 06 Jul 2009 Link to this post

    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?

  2. Miroslav
    Miroslav avatar
    922 posts

    Posted 07 Jul 2009 Link to this post

    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,
    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.
Back to Top