Passing values between Viewmodel in MVVM in WPF

mvvm, mvvm-light, silverlight, wpf

Solution

After a bit research I got the Current instance of my Mainviewmodel by the following Code.

MainViewModel mainViewModelInstaince = ServiceLocator.Current.GetInstance<MainViewModel>();

then I got all the methods and properties..and bound the datas from another viewmodel.

thanks to all..

Problem

I am developing WPF Application using MVVM light tool kit.I have a datagrid in my Mainwindow.I have created another window named "openfile" and their viewmodels.Main Window viewmodel class contain public property of type ObservableCollection MyList which is bound to the Datagrid.Can I able to fill this property from the openfile Viewmodel and and automatically bind to Datagrid? or can I able to pass a varaible to MainViewmodel and make a Call to a public function in the MainViewmodel from the OpenfileViewmodel? This is How I am calling MyPage From Menu bar. ``` private void NotificationMessageReceived(NotificationMessage msg) { switch (msg.Notification) { case Messages.MainVM_Notofication_ShowNewbWindow: new NewView().ShowDialog(); break; case Messages.MainVM_Notofication_ShowExistingWindow: new OpenExisitingView().ShowDialog(); break; case Messages.MainVM_Notofication_ShowotherWindow: newView().ShowDialog(); break; } } ``` Thanks in Advance. Roshil K

Original source