Add close button to tab header problem

6 posts, 0 answers
  1. Niclas Junsved
    Niclas Junsved avatar
    10 posts
    Member since:
    Dec 2009

    Posted 07 Dec 2010 Link to this post

    Hi,

    Following this How To I'm trying to add close buttons to my tab headers.

    The "Style" I'm using is exactly as in the example above, but located in a seperate xaml named "TabStyles".

    I have a UserControl "TabControl" with a grid containing my Telerik RadTabControl named "MyTabControl".

    In the code behind of the UserControl I do this:

     

    public TabControl()

     

    {

        InitializeComponent();

     

     

        TabStyles s = new TabStyles();

     

     

        Style s1 = (Style)s.Resources["ClosableStyle"];

     

        MyTabControl.ItemContainerStyle = s1;



    }

    I add my tab items programmatically like for example below:

     

     

    public void InitializeTabControl(IEnumerable<XElement> data, int startValue, bool readOnly)

     

    {

     

        _readOnly = readOnly;

        ParseXMLData(data, startValue);

     

        foreach (LIT item in TDetailsList)

     

        {

     

            var t = new RadTabItem();

     

            InitializeTabItem(t,item);

            MyTabControl.Items.Add(t);

        }

     

        if(MyTabControl.Items.Count <=0 )

     

        {

     

            var t = new RadTabItem();

     

            InitializeTabItem(t,

    new LIT());

     

            MyTabControl.Items.Add(t);

        }

     

        if(!_readOnly)

     

        AddEmptyTab();

    }

     

    The "ClosableStyle"  does not take any effect. Do I have to work with ObservableCollections?

    After having set the style of the "MyTabControl" I can see that I have the following exception in the ItemContainerStyle.TargetType.DeclaringMethod:

    DeclaringMethod = '((System.RuntimeType)((Telerik.Windows.Controls.ItemsControl)(TermsTabControl)).ItemContainerStyle.TargetType).DeclaringMethod' threw an exception of type 'System.InvalidOperationException'

    Regards,

    Niclas 







  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 10 Dec 2010 Link to this post

    Hello Niclas Junsved,

    I prepared a sample following the steps that you mentioned and the help article you have attached. Could you please give it a try and let me know if it works for you? If it doesn`t , we would highly appreciate if you send us your project or an isolated part demonstrating the issue you have come up with. Thank you in advance.

    Best wishes,
    Petar Mladenov
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  3. DevCraft banner
  4. Jose
    Jose avatar
    16 posts
    Member since:
    Dec 2010

    Posted 28 Dec 2010 Link to this post

    Hi.

    I have a similar situation but with a slight difference.

    I tried to follow the steps in this article
    http://www.telerik.com/help/silverlight/radtabcontrol-how-to-add-close-button-to-the-tab-headers.html

    but in my application i dont create the tabs dynamically from a collection. Basically my application starts with one tab (shows a list of users) and a double click on a record would trigger the creation of a new tab. That works perfect. The only problem is that the style is not being applied. I guess it has to do with the fact that i am not binding the creation of my tabs to any collection.

    All i want is to have the style applied to my tabs whenever i create them and i can't get it to work. I have been tweaking that sample code with no success.

    Any help would be highly appreciate it.
  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 30 Dec 2010 Link to this post

    Hello Niclas Junsved,

    Please check out the attached sample and let me know if it satisfies you completely.

    Best wishes,
    Petar Mladenov
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  6. Jose
    Jose avatar
    16 posts
    Member since:
    Dec 2010

    Posted 07 Jan 2011 Link to this post

    Thank you so much for your example.

    It works for me perfectly fine.

    I have a new question thou.

    Everytime i create a new tab, i want to have certain fields automatically set, like the text of the tab, for example, with the name of the Customer i double clicked on on the grid. I went to the UserControl Resource and added in the HeaderTemplate/ContentControl Content={Binding FirstName} />

    In my code-behind, when i add a new tab (following the example you provided me) i pass the Customer object to the DataContext of the new created tab... but no success. I thought it would work since i am setting the DataContext for this RadTabItem.

    Is there anything i might be doing incorrectly? Thank You
  7. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 12 Jan 2011 Link to this post

    Hi Niclas Junsved,

    The beast way to achieve the described approach is to create a ViewModel class that will hold Header or Title property and Content property corresponding to RadTabItem`s Header and Content. Please check out the attached solution and let me know if it satisfies you completely.

    Kind regards,
    Petar Mladenov
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Back to Top
DevCraft banner