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

How to disable tabs on a bound collection

1 Answer 154 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
Asela
Top achievements
Rank 1
Asela asked on 07 Oct 2011, 05:30 AM
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

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 11 Oct 2011, 12:28 PM
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 >>

Tags
TabControl
Asked by
Asela
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or