CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2009

    View and ViewModel communication in MVVM pattern in WPF


    I have been experiencing one typical problem in MVVM implementation in WPF based XBAP application. If anyone can through some light then it would be great help for me. As I am reaching to deadline of project and this (V to VM) communication seems to be biggest trouble for me. I have looked several articles and samples over the Internet but nothing seems to be helpfull for me.

    My Requirement

    I have a Main view (XAML page), this page contains one tab control having four tab items and each tab item has a grid control (we are using Xceed grid).
    Let me explain this situation more precisely-
    I have a view (Name EmployeeView), this view is nothing but a XAML page. In this view I have a tab control (Name EmploeeInfo). This tab control has four tab items (Name PersonalInfo, ProfessionalInfo, SocialInfo and FinancialInfo). Each tab item has one grid (Xceed grid- a .NOT compatible third party control) where I have to display the respective information.

    I have created one user control (XAML page) for each tab and placed all user controls in EmployeeView, so this way I have total 5 views (one EmployeeView which is my main view and four for user controls), I also have 5 ViewModels (one for EmployeeView which is my MainViewModel and four for user controls)

    I hope I have made myself clear in explaining the situation.

    My Problem

    I have to load the respective data only when the user clicks on the associated tab item i.e. I want to fetch personal information from model only when user clicks on PersonalInfo tab item, and want to fetch Social information from model when user clicks on SocialInfo tab item and so on...

    I created ICommand in each ViewModel and bind that ICommand in respective view, now if I create instance of each ViewModel in MainViewModel then all tabls load data when the page loads, if I do not do not instantiate the all ViewModels in MainViewModel and instantiate them on-demand when they are clicked then my ViewModel gets data from Model but View does not get refershed to display the data, in this case all four tabs remain blank.

    I have looked into many sampes but all samples load data initially but I want it on-demand....

    If anyone can show me the way to solve this problem then it would be a great help for me.....

    Thanks in advance.


  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004

    Re: View and ViewModel communication in MVVM pattern in WPF

    Does your model implement INotifyPropertyChange event?

    Can you post a simplified version of your model?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.