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

Setting Tab Content

3 Answers 153 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
None
Top achievements
Rank 1
None asked on 17 Dec 2013, 07:35 PM
I was trying to get the "Databinding" tab control demo working that allows you to dynamically add and remove tabs, and I don't see how to set the content for the currently selected tab. This is what I would like to do.

I have a search button. When I press the search button, I want to be able to dynamically add content to the selected tab. The content should remain when the user switches tabs as well(I am assuming for this I just need to set the IsContentPerserved flag). I would like to be able to do this in the code-behind, as I am pulling data with entity framework to populate a user control, which I will then put in the selected tab. How would I do this? Thank you.

3 Answers, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 20 Dec 2013, 03:20 PM
Hi Laura,

As you can see in the demo, the ContentTemplate of the RadTabItem is set to a DataTemplate hosting an empty Grid component. In your particular case you can create a custom DataTemplate which will define how the content of the tabs will be structured.

Furthermore, you will be able to fill that DataTemplate with data from your ViewModel (your entities respectively) by using Bindings.

I hope this information is helpful.

Regards,
Pavel R. Pavlov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
None
Top achievements
Rank 1
answered on 24 Dec 2013, 03:51 PM
So every time ANY tab gets rendered(including the ones in the demo where you can add/remove them), it will render the DataTemplate, and it is the job of the view model for each tab to add it's own content? I guess I was a little confused at how I would add a new tab(like in the demo with the + button) and set the content for that new tab. Or in this case, the view model for that specific tab. Thanks.
0
Pavel R. Pavlov
Telerik team
answered on 27 Dec 2013, 01:45 PM
Hi,

You need to keep in mind that the RadTabControl is used in MVVM scenario. This means that the control receives a collection of business items as ItemsSource and uses its ItemTemplate (to structure the header) and ContentTemplate (to structure the content) properties to create RadTabItems.

In your particular case you need to expose properties in the TabViewModel that will hold the information that will be visualized in the content of the RadTabItems. Furthermore, in the DataTemplate called "ContentTemplate" you need to expose controls that will be visualized in the content of each RadTabItem. Also, you will need to use bindings to the properties exposed in the TabViewModel in order to visualize your business data. You can see how the "TabItemTemplate" is structured and follow the same approach to create your own ContentTemplate.

I hope this information is helpful.

Regards,
Pavel R. Pavlov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
TabControl
Asked by
None
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
None
Top achievements
Rank 1
Share this question
or