Dynamic tab content

3 posts, 0 answers
  1. Greg Brondo
    Greg Brondo avatar
    13 posts
    Member since:
    Sep 2009

    Posted 11 May 2010 Link to this post

    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. Greg Brondo
    Greg Brondo avatar
    13 posts
    Member since:
    Sep 2009

    Posted 12 May 2010 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 15 May 2010 Link to this post

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