Disabling a tab from within a UserControl

2 posts, 0 answers
  1. GEB
    GEB avatar
    228 posts
    Member since:
    Dec 2008

    Posted 09 Jun 2009 Link to this post

    Assume that I have three tabs: Tab1, Tab2, and Tab3.  In my XAML that creates the tabs, each has a UserControl that is used to display the page for that tab.  I want to disable a tab based on the user interaction within the UserControl,  How can that UserControl disable/enable a tab in this fashion?
  2. Kiril Stanoev
    Kiril Stanoev avatar
    1508 posts

    Posted 11 Jun 2009 Link to this post

    Hello Gary,

    In the attachment you can find a sample project demonstrating your scenario.
    The easiest approach to this task is to create an event in the UserControl.
    In the event handler you can compare the UserControl that has raised the event and the content of the each TabItem. When they match, simply disable the TabItem.

    1 private void MyUserControl_Disable(object sender, EventArgs e) 
    3     MyUserControl userControl = sender as MyUserControl; 
    4     if (userControl != null
    5     { 
    6         foreach (RadTabItem tabItem in RadTabControl1.Items) 
    7         { 
    8             if (tabItem.Content == userControl) 
    9             { 
    10                 tabItem.IsEnabled = !tabItem.IsEnabled; 
    11             } 
    12         } 
    13     } 

    The sample attached is pretty self-explanatory.

    Another way is to add a public property to the UserControl which is of type RadTabItem. This property, however, can only be set in code-behind. So if you are creating TabItems dynamically, you can take the approach with the property.

    If you have any additional questions or comments, contact us as soon as possible.

    Kiril Stanoev
    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.
  3. DevCraft R3 2016 release webinar banner
Back to Top