Is there a way whereby I can identify a ChildViewModel instance, which was created by prism's ViewModelLocator, upon opening it's corresponding window?
I would like to trigger that the ChildViewModel should load it's data, based on parameters originating from the MasterViewModel.
In code, in MasterViewModel
has an ICommand
in a which is responsible for requesting opening a new child window by publishing an event, and there is a corresponding subscriber.
public ICommand OpenNewChildWindow()
{
Publish(new OpenNewChildWindowPubSubEvent());
// Maybe I can publish a new PubSubEvent here
// but how can I target just the recently created ChildViewModel?
}
Notice that the MasterViewModel
knows nothing about the UI implementation.
The the subscriber calls ShowWindow
method on a custom WindowManager
which basically resolves the View (Window in this instance) which corresponds to the ViewModel which was passed in.
public void ShowWindow(Type viewModelType)
{
Type view = ResolveView(viewModelType);
Window w = (Window)Activator.CreateInstance(view);
w.Show();
}
The xaml for the window the appropiate
ViewModelLocator.AutoWireViewModel="True"