본문 바로가기

.NET/MVVM Light

[MVVM-Light]ViewModel 간 values 전달

The easiest way is to pass MainWindowViewModel's instance to OpenFileViewModel: 

public class OpenFileViewModel 
{ 
    private MainWindowViewModel _parent; 
 

public OpenFileViewModel(MainWindowViewModel parent) 
    { 
          _parent = parent; 
    }

 

 After that you can call/access any public method/property in MainWindowViewModel: 

 foreach (var item in _parent.myList) 
{ 
    ... 
} 

 

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

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