private static void AddDialog(IDialogViewModel viewModel, ObservableCollection <IDialogViewModel> collection, Window owner) { // find the global resource that has been keyed to this view model type var resource = Application.Current.TryFindResource(viewModel.GetType()); if (resource == null) { return; } // is this resource a presenter? if (IsAssignableToGenericType(resource.GetType(), typeof(IDialogBoxPresenter <>))) { resource.GetType().GetMethod("Show").Invoke(resource, new object[] { viewModel }); collection.Remove(viewModel); } // is this resource a dialog box window? else if (resource is Window) { var userViewModel = viewModel as IUserDialogViewModel; if (userViewModel == null) { return; } var dialog = resource as Window; dialog.DataContext = userViewModel; DialogBoxes[userViewModel] = dialog; userViewModel.DialogClosing += (sender, args) => collection.Remove(sender as IUserDialogViewModel); dialog.Closing += (sender, args) => { if (!(bool)dialog.GetValue(ClosingProperty)) { dialog.SetValue(ClosingProperty, true); userViewModel.RequestClose(); if (!(bool)dialog.GetValue(ClosedProperty)) { args.Cancel = true; dialog.SetValue(ClosingProperty, false); } } }; dialog.Closed += (sender, args) => { Debug.Assert(DialogBoxes.ContainsKey(userViewModel)); DialogBoxes.Remove(userViewModel); return; }; dialog.Owner = owner; if (userViewModel.IsModal) { dialog.ShowDialog(); } else { dialog.Show(); } } }
public SlideCustomDialog ResolveDialog(IDialogViewModel dialogViewModel) { var dialogType = dialogViewModel.DialogType ?? ResolveDialogType(dialogViewModel.GetType()); var dialog = CreateDialog(dialogType); if (!(dialog is SlideCustomDialog)) { throw new ArgumentException("Page for '" + dialogViewModel.GetType().Name + "' should be of type 'BasePage' instead of '" + dialogType.Name + "'"); } dialog.BindingContext = dialogViewModel; return(dialog as SlideCustomDialog); }
private static void AddDialog(IDialogViewModel viewModel, ObservableCollection <IDialogViewModel> collection, Window owner) { var resource = owner.TryFindResource(viewModel.GetType()); if (resource == null) { return; } if (resource is DefaultRibbonWindow dialog) { var userViewModel = viewModel as IUserDialogViewModel; if (userViewModel == null) { return; } dialog.DataContext = userViewModel; DialogBoxes[userViewModel] = dialog; userViewModel.DialogClosing += (sender, args) => collection.Remove(sender as IUserDialogViewModel); dialog.Closing += (sender, args) => { if (!(bool)dialog.GetValue(ClosingProperty)) { dialog.SetValue(ClosingProperty, true); userViewModel.RequestClose(); if (!(bool)dialog.GetValue(ClosedProperty)) { args.Cancel = true; dialog.SetValue(ClosingProperty, false); } } }; dialog.Closed += (sender, args) => { Debug.Assert(DialogBoxes.ContainsKey(userViewModel)); DialogBoxes.Remove(userViewModel); return; }; dialog.Owner = owner; if (userViewModel.IsModal) { dialog.ShowDialog(); } else { dialog.Show(); } } }