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

How to add a tab item programatically

3 Answers 1042 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
hkdave95
Top achievements
Rank 2
hkdave95 asked on 19 Oct 2008, 08:10 PM
Hi

I need to add a tab control programmatically.

The item I am adding is a class containing amongst other things the Description to be diaplayed on the tab.

Do you have any examples of this.

Kind Regards

David

3 Answers, 1 is accepted

Sort by
0
Miroslav
Telerik team
answered on 21 Oct 2008, 12:05 PM
Hi David,

Yes, you can add a TabItems programmatically like so:

tabControl.Items.Add(new RadTabItem()  
    {  
        Header = "My Header",  
        Content = "My Content" 
    });  
 

Of course it is always better to use business objects and bindings. To do so:

1. Set the ItemsSource property to an (observable) collection of your items
2. Provide style or DataTemplate bindings for the control (in xaml).

For example style bindings can be specified this way:

<nav:RadTabControl x:Name="tabControl">  
    <nav:RadTabControl.ItemContainerStyle>  
        <Style TargetType="nav:RadTabItem">  
            <Setter Property="Header" 
                    Value="{Binding Description}" />  
            <Setter Property="Conent" 
                    Value="{Binding Content}" />  
        </Style>  
    </nav:RadTabControl.ItemContainerStyle>  
</nav:RadTabControl> 

For the above code you need an object that has Description and Content properties.

All the best,
Miroslav
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
dbernett
Top achievements
Rank 2
answered on 17 Oct 2012, 04:59 PM

Brand new to WPF.  I have a main window with your Ribbon Tab at top with buttons to open different windows. 

Could you please tell me the technique to open windows inside a Rad Tab Control below the Ribbon Tab.  I need to dynamically build out the tabs as different windows are opened, and to close the tabs.

Thanks so much!

0
Stefan
Telerik team
answered on 19 Oct 2012, 11:55 AM
Hello David,

If I get you right, you need something like this example. If you need to check the example in WPF you can run our demos from here and navigate to RadTabControl's DataBinding example. The only thing you might need to change is to move the button that adds a new RadTabItem from RadTabItem's header in the RadRibbonTabs.

If you need further assistance don't hesitate to contact us.

Regards,
Stefan
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
TabControl
Asked by
hkdave95
Top achievements
Rank 2
Answers by
Miroslav
Telerik team
dbernett
Top achievements
Rank 2
Stefan
Telerik team
Share this question
or