views:

136

answers:

2

I have a number of usercontrols inside tabitems in a tabcontrol in a main Window. One user control per tabitem all inside a window.

After some code executes inside one of the controls (inside one of the tabitems), I want to enable/disable other tabitems.

How can I do it?

A: 

You can modify the enabled and visible properties:

tabPage1.Enabled = false;
tabPage1.Visible = false;

Think this fits the OP more:

FrameworkElement parent = userControl.Parent as FrameworkElement; // As is not needed, 'userControl' could be 'this'

if (FrameworkElement != null)
{
    parent.IsEnabled = false;
    parent.IsVisible = false;
}
Cory Charlton
This is pretty vague so feel free to ask questions.
Cory Charlton
Just noticed the 'wpf' tag. My example might not be applicable. Still haven't jumped on that bandwagon :-P
Cory Charlton
http://msdn.microsoft.com/en-us/library/system.windows.controls.tabitem_members.aspxLooks like you could use: tabItem1.IsEnabled = false; tabItem1.IsVisible = false;
Cory Charlton
Sorry its hard to explain. The problem is that inside the usercontrol, which is inside the tabitem, which is inside the window - i can't access the tabitem like tabitem.IsEnabled. If I use the window code behind file I could access it like that, but I have no code there. Really its just for presentation. I am trying to access the tabitem properties from the usercontrol code behind. Sorry... its not the easiest thing to explain!
baron
I think I understand. The code to disable is in your 'UserControl' and you need it to figure out what it is attached to. I can't post code correctly in a comment so check my new answer.
Cory Charlton
Err my editted answer rather :)
Cory Charlton
+1  A: 

Normally you would do logic in the Model object, so the event that you have 'executing' would alter the Model (via method call), then the Model would update it's internal state, which would be reflected by DependencyProperties, which you would bind your UI via Xaml.

Simeon Pilgrim
Agree. Use a property in the main ViewModel "Tab1Enabled" and bind a trigger to it.
adrianm
Can you please elaborate? How would you bind a trigger to it?
baron