private Window GetCustomWindow(string viewKey, ModalDialogViewModelBase viewModel) { if (string.IsNullOrEmpty(viewKey)) throw new ArgumentException("viewKey"); if (null == viewModel) throw new ArgumentException("viewModel"); var viewRegistry = ModalViewRegistry.Instance; if (!viewRegistry.ContainsKey(viewKey)) throw new ArgumentException(string.Format("the key is not present in the registry: {0}", viewKey)); var userControl = viewRegistry.GetViewByKey(viewKey); // Get the UserControl. var modalWindow = new ModalCustomMessageDialog { // Set the content of the window as the user control DataContext = viewModel, // Set the data context of the window as the ViewModel Owner = AppData.AppMainWindow, // Set the owner of the modal window to the app window. WindowStartupLocation = WindowStartupLocation.CenterOwner, ShowInTaskbar = false, //Set content ActualContent = userControl, //Adjust height and width SizeToContent = SizeToContent.WidthAndHeight, }; modalWindow.Closed += CleanModalWindow; return modalWindow; }
void IMessagingService.ShowCustomMessage(string viewKey, ModalDialogViewModelBase viewModel) { var modalWindow = GetCustomWindow(viewKey, viewModel); modalWindow.Show(); }