Friday, 9 August 2013

single viewmodel instance with multiple views

single viewmodel instance with multiple views

In my WPF app, I have two views to represent a single viewmodel. Both the
DataContexts are set with the single instance of the viewmodel. But, the
property change notification is not happening and the connection is lost
between the views and viewmodel. The idea is, if the user changes data in
one view should reflect the change in other view immediately. How do I
attach a single viewmodel instance with multiple views?
public MainWindow() {
InitializeComponent();
MembersViewModel userView = new MembersViewModel();
MemberView.DataContext = userView;
MemberPreview.DataContext = userView;
}
I have two views MemberView and MemberPreview and both are using the
MembersViewModel. The MemberView is the detailed view and MemberPreview is
kind of subset. When I change something in the MemberView (Ex:
MemberName), I want the change to reflect in the MemberPreview.

No comments:

Post a Comment