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

Run through RadTabItems when a RadTabItem has a view model

3 Answers 127 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 26 Sep 2016, 11:36 AM

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.

3 Answers, 1 is accepted

Sort by
0
David
Top achievements
Rank 1
answered on 26 Sep 2016, 11:46 AM
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?
0
Accepted
Kiril Vandov
Telerik team
answered on 28 Sep 2016, 01:47 PM
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.
0
David
Top achievements
Rank 1
answered on 28 Sep 2016, 03:41 PM

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.

 

 

Tags
TabControl
Asked by
David
Top achievements
Rank 1
Answers by
David
Top achievements
Rank 1
Kiril Vandov
Telerik team
Share this question
or