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

Edit the visual representation of data bound to itemsource

3 Answers 28 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
prog1
Top achievements
Rank 1
prog1 asked on 08 Sep 2010, 09:29 AM
Hi Telerik-Team,

at the moment I have a look at the RadTabControl and I'm a little bit confused because of the binding.
If I bind my dataobject to itemsource, for every item there is a RadTabItem generated.
With itemsource I can only access the data, which is working well if I'm working with MVVM for example.

Is there a way to access the generated RadTabItems? For example another collection with contains the visual elements?

3 Answers, 1 is accepted

Sort by
0
prog1
Top achievements
Rank 1
answered on 08 Sep 2010, 11:01 AM
I can do it like this:

foreach (var item in data)
{
    RadTabItem tab = new RadTabItem();
    tab.Content = item;
    tab.Header = item;
    tab.ContentTemplate = (DataTemplate)this.Resource["ContentTemplate"];
    tab.HeaderTemplate = (DataTemplate)this.Resources["HeaderTemplate"];
    chap.Items.Add(tab);
}

I have to do this in codebehind and set Content and Header to the data. Know this, because I had the same problem at the RadBook.
(TicketId: 337374).
Don't really understand why DataContext is not working in this two cases and I have to set the Conten with a DataObject.
Isn't Content almost made for controls and DataContext for the data? Anyway, I got it.
0
Miro Miroslavov
Telerik team
answered on 13 Sep 2010, 06:53 AM
Hi prog1,

The better way is to use the first approach with binding to ItemsSource. Later you can get the generated RadTabItems using the following code:

RadTabItem item = tabControl1.ItemContainerGenerator.ContainerFromItem(dataItem) as RadTabItem;

You can also use the ContainerFromIndex(int) method. The ItemContainerGenerator is the object that creates RadTabItem object for-each data object, thus it contains the mapping between the containers and the data item.

Can you give it a try and let me know if this is what you need? 
Thank you.

Regards,
Miro Miroslavov
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
0
prog1
Top achievements
Rank 1
answered on 13 Sep 2010, 08:24 AM
Very nice Miro,

did not see the ItemContainerGenerator.
Now it's working very well :-)
Tags
TabControl
Asked by
prog1
Top achievements
Rank 1
Answers by
prog1
Top achievements
Rank 1
Miro Miroslavov
Telerik team
Share this question
or