Enable/Disable TabItem when Data Binding

5 posts, 1 answers
  1. Keith Pelletier
    Keith Pelletier avatar
    2 posts
    Member since:
    Feb 2010

    Posted 18 May 2010 Link to this post

    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.

  2. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 20 May 2010 Link to this post

    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.
  3. DevCraft banner
  4. Keith Pelletier
    Keith Pelletier avatar
    2 posts
    Member since:
    Feb 2010

    Posted 20 May 2010 Link to this post

    Hello Tina...

    This worked perfectly... thanks much...

    Keith
  5. Andy Fry
    Andy Fry avatar
    9 posts
    Member since:
    Nov 2009

    Posted 14 Jul 2010 Link to this post

    This example doesn't work for me. I downloaded it and converted it to a VS2010 project.

    None of the tabs are ever disabled.
  6. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 20 Jul 2010 Link to this post

    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
Back to Top
DevCraft banner