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

Access VieModel of TabControl in UserControl

8 Answers 200 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
ITA
Top achievements
Rank 1
ITA asked on 17 Dec 2014, 04:22 PM
Hi,

using c# .NET 4.5, Wpf, RadTabControl (DataContext is a TabViemodel).

I bound a VieModel on my RadTabControl. With a Command on a RadButton, i add a new TAbItem and load a UserControl
as Contet.

On initializing the USerControl i try to access the ViewModel from the TAbControl, but without any success. As you can see on
the attached File the SelectedContent is my VieModel, but the var yyy is null?

Thanks
Best Regards
Rene

8 Answers, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 22 Dec 2014, 10:37 AM
Hi Rene,

I am not sure how exactly you load the UserControl into the RadTabControl. I implemented an MVVM approach in the attached project to demonstrate how a UserControl should be loaded.

Please take a look at it and let me know if you need any further assistance.

Regards,
Pavel R. Pavlov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
ITA
Top achievements
Rank 1
answered on 22 Dec 2014, 12:52 PM
Hi Pavel,

this is how i load the UserControl into the RadTabControl. If the right button is in an GridView line, how do i transfer the selected
Item of the GridView into the new TabItem?

Example:
On my UserControl is a RadGridView, which contains a MVVM of Taks. Now i click the RadButton in one Row of the GridView.
The New Tab opens a loads the right UserControl. But how do i get the Item from the GridView?

Thanks
Best Regards
Rene
0
Martin Ivanov
Telerik team
answered on 25 Dec 2014, 11:34 AM
Hello Rene,

I modified the project that Pavel sent you and now it demonstrates TabControl and GridView controls. The GridView rows contain a Button and when you click it a new TabItem is added with the view model of button's container row. 

The project also demonstrates adding of a new item in the TabControl on selection changed. Please give the project a try and let  me know if it works for you.

Regards,
Martin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
ITA
Top achievements
Rank 1
answered on 28 Dec 2014, 01:49 PM
Hi Martin,

sorry can't open the project!

Thanks
Rene
0
Martin Ivanov
Telerik team
answered on 29 Dec 2014, 11:36 AM
Hello Rene,

You can try to open the project through the Visual Studio's File menu. To do so you can click on File --> Open -- > Project/Solution.

I also attached the project files so you can create new project and use the code from them if the project's opening does not work for you.

Regards,
Martin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
ITA
Top achievements
Rank 1
answered on 30 Dec 2014, 09:22 AM
Hi Martin,

thanks so much, but i have one more question. I attached a Screenshot of the UserUserControl Initialization on the new Tab.
But why is "ti = null"?

I need a propertie out of the TabViewModel to load the selected Item from the Control before!

Thanks
Best Regards

All the best for 2015!

0
ITA
Top achievements
Rank 1
answered on 30 Dec 2014, 09:28 AM
sorry the file...
0
ITA
Top achievements
Rank 1
answered on 30 Dec 2014, 11:47 AM
Hi Martin,

thanks a lot, problem is solved!

Best Regards
Rene
Tags
TabControl
Asked by
ITA
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
ITA
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or