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

Add close button to tab header problem

5 Answers 91 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
Niclas Junsved
Top achievements
Rank 1
Niclas Junsved asked on 07 Dec 2010, 10:49 PM
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 







5 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 10 Dec 2010, 04:33 PM
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
0
Jose
Top achievements
Rank 1
answered on 28 Dec 2010, 08:46 PM
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.
0
Petar Mladenov
Telerik team
answered on 30 Dec 2010, 02:38 PM
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
0
Jose
Top achievements
Rank 1
answered on 07 Jan 2011, 06:05 PM
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
0
Petar Mladenov
Telerik team
answered on 12 Jan 2011, 01:12 PM
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>>
Tags
TabControl
Asked by
Niclas Junsved
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Jose
Top achievements
Rank 1
Share this question
or