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

Enable/Disable TabItem when Data Binding

4 Answers 234 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
Keith Pelletier
Top achievements
Rank 1
Keith Pelletier asked on 18 May 2010, 08:39 PM

Let's say I have a Tab Control Bound to a collection on a ViewModel like so:

 <telnav:RadTabControl x:Name="Objectives" 
                              Grid.Row="1" 
                              DisplayMemberPath="Name" 
                              ItemsSource="{Binding Path=PresentationElements}" 
                              SelectedItem="{Binding Path=ActiveElement, Mode=TwoWay}" 
                              ContentTemplateSelector="{StaticResource GenericViewSelector}" 
                              Background="{x:Null}"   
                              BorderBrush="{x:Null}"   
                              ></telnav:RadTabControl> 

In this case, PresentationElements is an ObservableCollection of ViewModels on a parent ViewModel, which is the DataContext for the View (and thus for the TabControl as well). As you can see, I'm using a ContentTemplate selector... this just unites a View with the ViewModel. 

This works quite happily. I get a set of tabs and appropriate content (Views) and headers. Now, I want to bind the IsEnabled property of each TabItem to a suitable property on the Data Context for that TabItem. Does that make sense?

Let's say I have ViewModelA, ViewModelB, and ViewModelC in my Observable. That will give me three TabItems (TabItem1, TabItem2, TabItem3, respectively) in the TabControl. I want to bind the IsEnabled property of TabItem1 to the IsEnabled property of ViewModelA, etc. I can't figure out how to do that.

I can't set it in the ItemsContainerStyle because you can use binding in Style Setters. I'm sure I'm missing something simple... any help would be quite helpful.

4 Answers, 1 is accepted

Sort by
0
Accepted
Tina Stancheva
Telerik team
answered on 20 May 2010, 12:35 PM
Hello Keith Pelletier,

You can accomplish this with ContainerBinding. A telerik’s container binding for Silverlight is the same as a style binding in WPF. Basically it binds a property of the container (RadTabItem in this case) to a property from the business model:
<telerik:ContainerBindingCollection x:Key="ContainerBinding">
    <telerik:ContainerBinding PropertyName="IsEnabled" Binding="{Binding IsEnabled, Mode=TwoWay}"/>
</telerik:ContainerBindingCollection>

Also you will need to set the telerik:ContainerBinding.ContainerBindings property in the header template (ItemTemplate) of the RadTabItems.

I prepared a sample project illustrating this approach. Take a look at it and let me know if this is what you had in mind.

Regards,
Tina Stancheva
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.
0
Keith Pelletier
Top achievements
Rank 1
answered on 20 May 2010, 10:45 PM
Hello Tina...

This worked perfectly... thanks much...

Keith
0
Andy Fry
Top achievements
Rank 1
answered on 14 Jul 2010, 04:27 PM
This example doesn't work for me. I downloaded it and converted it to a VS2010 project.

None of the tabs are ever disabled.
0
Valentin.Stoychev
Telerik team
answered on 20 Jul 2010, 07:40 AM
Hi Andy Fry,

It seems like there is a problem in the conversion from VS2008 to VS10. I modified the new solution to work and and I'm attaching it here again.

Best wishes,
Valentin.Stoychev
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
Keith Pelletier
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Keith Pelletier
Top achievements
Rank 1
Andy Fry
Top achievements
Rank 1
Valentin.Stoychev
Telerik team
Share this question
or