This is a migrated thread and some comments may be shown as answers.
Binding TabItems Visibility Property.
1 Answer 29 Views
This is a migrated thread and some comments may be shown as answers.
anester
Top achievements
Rank 1
anester asked on 17 Sep 2010, 07:30 PM
I want to hide and display a tab based on a IsVisible property on a QTab that will be bound in the RadTab's ItemSource.

Here are the classes I am using
public class QTabs
{
    public ObservableCollection<QTab> Tabs { get; set; }
    public QTabs()
    {
        Tabs = new ObservableCollection<QTab>
            (
                new QTab[] {
                    new QTab { Header="Header 1",Value="Value 1"},
                    new QTab { Header="Header 2",Value="Value 2"},
                    new QTab { Header="Header 3",Value="Value 3", IsVisible= Visibility.Collapsed},
                    new QTab { Header="Header 4",Value="Value 4"},
                    new QTab { Header="Header 5",Value="Value 5"}
                }
            );
    }
}
 
public class QTab
{
    public string Header { get; set; }
    public string Value { get; set; }
    public Visibility IsVisible { get; set; }
    public QTab()
    {
        IsVisible = Visibility.Visible;
    }
}

MainPage.xaml.cs
public MainPage()
{
    AllTabs = new QTabs();
    InitializeComponent();
    DataContext = this;
}
xaml snippets
<my3:RadTabControl x:Name="tabscon" Grid.Row="1" DataContext="{Binding AllTabs}" ItemsSource="{Binding Tabs}">
    <my3:RadTabControl.ItemContainerStyle>
        <Style TargetType="my3:RadTabItem">
            <Setter Property="HeaderTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <TextBlock Text="{Binding Header}"/>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </my3:RadTabControl.ItemContainerStyle>
</my3:RadTabControl>

The above works so the binding is fine but when I add
<Setter Property="Visibility" Value="{Binding IsVisible}"/>
To the style I get an error that says I cannot set a readonly property.  Is there any way I can bind the the TabItems Visibility so I can dynamically had the tab.

Thanks

1 Answer, 1 is accepted

Sort by
0
Viktor Tsvetkov
Telerik team
answered on 20 Sep 2010, 05:51 PM
Hi anester,

In this case you can use ContainerBindings. Could you please examine the attached sample project and if you have further questions do not hesitate to ask?

Best wishes,
Viktor Tsvetkov
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
Asked by
anester
Top achievements
Rank 1
Answers by
Viktor Tsvetkov
Telerik team
Share this question
or