Access VieModel of TabControl in UserControl

9 posts, 0 answers
  1. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 17 Dec 2014 Link to this post

    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
  2. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1183 posts

    Posted 22 Dec 2014 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 22 Dec 2014 in reply to Pavel R. Pavlov Link to this post

    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
  5. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 25 Dec 2014 Link to this post

    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.

     
  6. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 28 Dec 2014 in reply to Martin Link to this post

    Hi Martin,

    sorry can't open the project!

    Thanks
    Rene
  7. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 29 Dec 2014 Link to this post

    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.

     
  8. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 30 Dec 2014 in reply to Martin Link to this post

    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!

  9. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 30 Dec 2014 in reply to Martin Link to this post

    sorry the file...
  10. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 30 Dec 2014 in reply to ITA Link to this post

    Hi Martin,

    thanks a lot, problem is solved!

    Best Regards
    Rene
Back to Top
UI for WPF is Visual Studio 2017 Ready