private static void AddDialog(IDialogViewModel viewModel, IDialogViewModelCollection 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, owner }); 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 bool Show(IDialogViewModelCollection collection) { collection.Add(this); return(this.Result); }
public MessageBoxResult Show(IDialogViewModelCollection collection) { collection.Add(this); return(this.Result); }
public static void SetDialogViewModels(DependencyObject source, IDialogViewModelCollection value) { source.SetValue(DialogViewModelsProperty, value); }
public virtual void Show(IDialogViewModelCollection dialogs) { dialogs.Add(this); }