This was previously posted in StackOverflow, I just moved to here...
I am using VS2008, MVVM, WPF, Prism to make a mutiple window CRM Application.
I am using
MidWinow in my
MainWindow, I want
ViewModelwould able to make request to
ChildWindow(from WPF Toolkit),
Window(the Window type).
ViewModelcan get the
MainWindowhave control on all opened window types.
Here is my current approach:
Dictionary of each of the windows type and stores them into MainWindow class.
For 1, i.e in a
CustomerInformationViewModel can execute
EditCommand and use
EventAggregator to tell MainWindow to open a new
CustomerEditView ceView = new CustomerEditView (); CustomerEditViewModel ceViewModel = CustomerEditViewModel (); ceView.DataContext = ceViewModel; ChildWindow cWindow = new ChildWindow(); cWindow.Content = ceView; MainWindow.EvntAggregator.GetEvent<NewWindowEvent>().Publish(new WindowEventArgs(ceViewModel.ViewModeGUID, cWindow )); cWindow.Show();
Notice that all my
ViewModel will generates a
Guid for help identifies the
MainWindow's dictionary. Since I will only be using 1 View 1 ViewModel for every Window.
For 2. In
CustomerInformationViewModel I can get
OnClosing event from
CustomerEditViewModel can use
Guid to tell MainWindow to close the ChildWindow.
Here is little question and problems:
Is it good idea to use Guid here? Or should I use HashKey from ChildWindow?
MainWindows contains windows reference collections. So whenever window close, it will get notifies to remove from the collection by
OnClosing event. But all the Windows itself doesn't know about its associated Guid, so when I remove it, I have to search for every KeyValuePair to compares...
I still kind of feel wrong associate ViewModel's Guid for ChildWindow, it would make more sense if ChildWindow has it own ID then ViewModel associate with it...
But most important, is there any better approach on this design? How can I improve this better?