Edit the visual representation of data bound to itemsource

4 posts, 0 answers
  1. prog1
    prog1 avatar
    61 posts
    Member since:
    Jul 2008

    Posted 08 Sep 2010 Link to this post

    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?
  2. prog1
    prog1 avatar
    61 posts
    Member since:
    Jul 2008

    Posted 08 Sep 2010 Link to this post

    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.
  3. DevCraft banner
  4. Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 13 Sep 2010 Link to this post

    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
  5. prog1
    prog1 avatar
    61 posts
    Member since:
    Jul 2008

    Posted 13 Sep 2010 Link to this post

    Very nice Miro,

    did not see the ItemContainerGenerator.
    Now it's working very well :-)
Back to Top