Run through RadTabItems when a RadTabItem has a view model

4 posts, 1 answers
  1. David
    David avatar
    18 posts
    Member since:
    Apr 2016

    Posted 26 Sep Link to this post

    First of all sorry if this question is already answered or it is very dummy.

     

    I was using several RadTabControls in my application, but I've reached a point that I need to use a view model istead of a RadTabItem and create them in codebehind on certain conditions for one of the RadTabCotrols.

    There is other function that does run through every RadTabControl retrieving all the RadTabItems by looking at the Item property. But it happens that one of my RadTabControls has a custom viewModel, so the cast to RadTabItem fails.

    I suppose that it is very logical to get the ViewModel from Items property when you have defined to have a viewmodel and want to run over all items, but I wonder if there is a generic way (accessor, list) of getting just the RadTabItem control that wraps the custom viewmodel and use the same method of running through all RadTabItems for all RadTabControls.

     

    Thanks in advance.

     

    David.

  2. David
    David avatar
    18 posts
    Member since:
    Apr 2016

    Posted 26 Sep Link to this post

    Before I posted I was thinking getting all childrens of type RadTabItem, but it seemed to me not a correct solution. Is there any better solution than that?
  3. UI for WPF is Visual Studio 2017 Ready
  4. Answer
    Kiril Vandov
    Admin
    Kiril Vandov avatar
    324 posts

    Posted 28 Sep Link to this post

    Hello David,

    You can easily determine if your items will a ViewModelItems or a TabItems if you are following the MVVM patter. For instance the ItemsSource property will be set only to your TabControl which has the custom viewModel. This could be your first point of detecting the change.
    However you can easily get the Containers (RadTabItems) which are generated for a particular items using the ItemContainerGenerator of the RadTabControl.
    foreach (var item in this.xTabControl.Items)
    {
        var container = this.xTabControl.ItemContainerGenerator.ContainerFromItem(item) as RadTabItem;
    }
    I hope this information helps. If this is not what you were looking for please provide us with a little more infrormation and example of your user case.

    Kind regards,
    Kiril Vandov
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  5. David
    David avatar
    18 posts
    Member since:
    Apr 2016

    Posted 28 Sep in reply to Kiril Vandov Link to this post

    Thank you very much. At the end I decided that having a view model would not give me the result I wanted, so I ended to removing it, anyway I will keep your mail for future reference.

     

     

Back to Top