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

Dynamic tab content

2 Answers 157 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
Greg Brondo
Top achievements
Rank 1
Greg Brondo asked on 12 May 2010, 04:39 AM
Why doesn't this work?

 

/// <summary>  
/// Satisfies req for IPartnerMessenger. Dynamically Loads Partner radtab content.  
/// </summary>  
/// <param name="PartnerType"></param>  
/// <param name="partner"></param>  
public void NotifyPartnerSelection(Type PartnerType, Partner partner)  
{  
    if (PartnerType == typeof(EmailPartner))  
    {  
        this._selectedPartner = (EmailPartner)partner;  
        this.PartnerRadTabItem.SetValue(RadTabItem.ContentProperty, new EmailPartnerView(this, (EmailPartner)partner));  
    }  
    else if (PartnerType == typeof(NamedCallPartner))  
    {  
        this._selectedPartner = (NamedCallPartner)partner;  
        this.PartnerRadTabItem.SetValue(RadTabItem.ContentProperty, new NamedCallPartnerView(this, (NamedCallPartner)partner));  
    }  
    else if (PartnerType == typeof(AnonymousCallPartner))  
    {  
        this._selectedPartner = (AnonymousCallPartner)partner;  
        this.PartnerRadTabItem.SetValue(RadTabItem.ContentProperty, new AnonymousCallPartnerView(this, (AnonymousCallPartner)partner));  
 
    }  
    else 
        ClientErrorHelper.ShowError(new Exception("Stuff went wrong"));  
 
    } 

 

I have tried it as just setting the content property directly as well. Basically it works for the first assignment to the content property and then all other setting attempts although the radtabitem.content property changes, the user control displayed in the tab does not change.

 

 

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Greg Brondo
Top achievements
Rank 1
answered on 12 May 2010, 10:10 PM
I have found a different way to do this. But it's not exactly what I want. This technique puts the tab at the back of the line.

private RadTabItem _partnerRadTabItem;  
        /// <summary> 
        /// Satisfies req for IPartnerMessenger. Dynamically Loads Partner radtab content.  
        /// </summary> 
        /// <param name="PartnerType"></param> 
        /// <param name="partner"></param> 
        public void NotifyPartnerSelection(Type PartnerType, Partner partner)  
        {  
            if (PartnerType == typeof(EmailPartner))  
            {  
                this.TabControl.Items.Remove(this.PartnerRadTabItem);  
                this.TabControl.Items.Remove(_partnerRadTabItem);  
                _partnerRadTabItem = new RadTabItem();  
                _partnerRadTabItem.Header = "Partner info";  
                _partnerRadTabItem.Content = new EmailPartnerView(this, (EmailPartner)partner);  
                this.TabControl.Items.Add(_partnerRadTabItem);  
            }  
            else if (PartnerType == typeof(NamedCallPartner))  
            {  
                this.TabControl.Items.Remove(this.PartnerRadTabItem);  
                this.TabControl.Items.Remove(_partnerRadTabItem);  
                _partnerRadTabItem = new RadTabItem();  
                _partnerRadTabItem.Header = "Partner info";  
                _partnerRadTabItem.Content = new NamedCallPartnerView(this, (NamedCallPartner)partner);  
                this.TabControl.Items.Add(_partnerRadTabItem);  
            }  
            else if (PartnerType == typeof(AnonymousCallPartner))  
            {  
                this.TabControl.Items.Remove(this.PartnerRadTabItem);  
                this.TabControl.Items.Remove(_partnerRadTabItem);  
                _partnerRadTabItem = new RadTabItem();  
                _partnerRadTabItem.Header = "Partner info";  
                _partnerRadTabItem.Content = new AnonymousCallPartnerView(this, (AnonymousCallPartner)partner);  
                this.TabControl.Items.Add(_partnerRadTabItem);  
            }  
            else  
                ClientErrorHelper.ShowError(new Exception("Stuff went wrong"));  
 
        } 

This.PartnerRadTabItem is a blank tab that is set in the xaml so that the tab appears to be there when the control first loads.
0
Miro Miroslavov
Telerik team
answered on 15 May 2010, 02:00 PM
Hi Greg Brondo,

Instead of using tab this.TabControl.Items.Add, you can use this.TabControl.Items.Insert and put them where you need.
Also i recommend you to use DataTemplates for you different tabs and DataTemplateSelector to choose which template is suitable based on your type that you set for Content of the tab.

Hope this helps you.

Sincerely yours,
Miro Miroslavov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
TabControl
Asked by
Greg Brondo
Top achievements
Rank 1
Answers by
Greg Brondo
Top achievements
Rank 1
Miro Miroslavov
Telerik team
Share this question
or