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

Disabling a tab from within a UserControl

1 Answer 55 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
GEB
Top achievements
Rank 1
GEB asked on 09 Jun 2009, 11:16 AM
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?

1 Answer, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 11 Jun 2009, 08:47 AM
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.

private void MyUserControl_Disable(object sender, EventArgs e) 
    MyUserControl userControl = sender as MyUserControl; 
    if (userControl != null
    { 
        foreach (RadTabItem tabItem in RadTabControl1.Items) 
        { 
            if (tabItem.Content == userControl) 
            { 
                tabItem.IsEnabled = !tabItem.IsEnabled; 
            } 
        } 
    } 

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.

Greetings,
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.
Tags
TabControl
Asked by
GEB
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Share this question
or