How to disable tabs on a bound collection

2 posts, 0 answers
  1. Asela
    Asela avatar
    6 posts
    Member since:
    Jan 2011

    Posted 07 Oct 2011 Link to this post

    Hi there,

    I have a dynamic collection which I bind to the tab control, however, I would also like to be able to enable / disable the tabs based on some criteria, however, I am unsure of what to  bind to so I Can disable tabbing to the control.

    I followed your basic demo for binding to a collection please see code below

    <Grid>
            <Grid.DataContext>
                <WpfApplication3:MainWindowViewModel/>
            </Grid.DataContext>
            <telerik:RadTabControl ItemsSource="{Binding People}" >
                <telerik:RadTabControl.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}"/>
                    </DataTemplate>
                   
                </telerik:RadTabControl.ItemTemplate>
                <telerik:RadTabControl.ContentTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Age}"/>
                    </DataTemplate>
                </telerik:RadTabControl.ContentTemplate>
            </telerik:RadTabControl>
        </Grid>

    Thanks
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 11 Oct 2011 Link to this post

    Hi Asela,

     Supposing you are following the approach demonstrated in this help article, you can introduce boolean property in the Person class:

    public class Person
     {
         public Person(string name, int age)
         {
             this.Name = name;
             this.Age = age;
         }
         public string Name
         {
             get;
             set;
         }
         public int Age
         {
             get;
             set;
         }
     
         public bool Enabled { get; set; }
     }
    and bind it to the IsEnabled property of the corresponding RadTabItems via StyleBindings:
    <Grid.Resources>     
               <local:ViewModel x:Key="DataSource" />
                
               <Style TargetType="telerik:RadTabItem">
                   <Setter Property="IsEnabled" Value="{Binding Enabled, Mode=TwoWay}" />
               </Style>
     
               <DataTemplate x:Key="ContentTemplate">
                   <Grid>
                       <TextBlock Text="{Binding Age}" />
                   </Grid>
               </DataTemplate>
     
               </Grid.Resources>
    You can find this realized in the attached solution. Please let us know if this is what you need. Greetings,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top