June 4th, 2009, 07:55 AM
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.
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.
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.
June 9th, 2009, 06:04 AM
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?
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!