public void ShowDialog(string name, IDialogParameters parameters, Action <IDialogResult> callback) { try { parameters = UriParsingHelper.GetSegmentParameters(name, parameters); var view = CreateViewFor(UriParsingHelper.GetSegmentName(name)); var dialogAware = InitializeDialog(view, parameters); var currentPage = GetCurrentPage(); dialogAware.RequestClose += DialogAware_RequestClose; void DialogAware_RequestClose(IDialogParameters outParameters) { try { var result = CloseDialog(outParameters ?? new DialogParameters(), currentPage); if (result.Exception is DialogException de && de.Message == DialogException.CanCloseIsFalse) { return; } dialogAware.RequestClose -= DialogAware_RequestClose; callback?.Invoke(result); GC.Collect(); } catch (DialogException dex) { if (dex.Message != DialogException.CanCloseIsFalse) { callback?.Invoke(new DialogResult { Exception = dex, Parameters = parameters }); } } catch (Exception ex) { callback?.Invoke(new DialogResult { Exception = ex, Parameters = parameters }); } } if (!parameters.TryGetValue <bool>(KnownDialogParameters.CloseOnBackgroundTapped, out var closeOnBackgroundTapped)) { var dialogLayoutCloseOnBackgroundTapped = DialogLayout.GetCloseOnBackgroundTapped(view); if (dialogLayoutCloseOnBackgroundTapped.HasValue) { closeOnBackgroundTapped = dialogLayoutCloseOnBackgroundTapped.Value; } } InsertPopupViewInCurrentPage(currentPage as ContentPage, view, closeOnBackgroundTapped, DialogAware_RequestClose); PageUtilities.InvokeViewAndViewModelAction <IActiveAware>(currentPage, aa => aa.IsActive = false); PageUtilities.InvokeViewAndViewModelAction <IActiveAware>(view, aa => aa.IsActive = true); } catch (Exception ex) { var error = ex.ToString(); callback?.Invoke(new DialogResult { Exception = ex }); } }
/// <inheritdoc /> public void ShowDialog(string name, IDialogParameters parameters, Action <IDialogResult> callback) { try { parameters = UriParsingHelper.GetSegmentParameters(name, parameters); var view = CreateViewFor(UriParsingHelper.GetSegmentName(name)); var popupPage = CreatePopupPageForView(view); var dialogAware = InitializeDialog(view, parameters); if (!parameters.TryGetValue <bool>(KnownDialogParameters.CloseOnBackgroundTapped, out var closeOnBackgroundTapped)) { var dialogLayoutCloseOnBackgroundTapped = DialogLayout.GetCloseOnBackgroundTapped(view); if (dialogLayoutCloseOnBackgroundTapped.HasValue) { closeOnBackgroundTapped = dialogLayoutCloseOnBackgroundTapped.Value; } } if (!parameters.TryGetValue <bool>(KnownPopupDialogParameters.Animated, out var animated)) { animated = true; } var popupDialogLayoutIsAnimationEnabled = PopupDialogLayout.GetIsAnimationEnabled(view); popupPage.IsAnimationEnabled = popupDialogLayoutIsAnimationEnabled ?? true; dialogAware.RequestClose += DialogAware_RequestClose; void CloseOnBackgroundClicked(object sender, EventArgs args) { DialogAware_RequestClose(new DialogParameters()); } void DialogAware_RequestClose(IDialogParameters outParameters) { try { var result = CloseDialog(outParameters ?? new DialogParameters(), popupPage, view); if (result.Exception is DialogException de && de.Message == DialogException.CanCloseIsFalse) { return; } dialogAware.RequestClose -= DialogAware_RequestClose; if (closeOnBackgroundTapped) { popupPage.BackgroundClicked -= CloseOnBackgroundClicked; } callback?.Invoke(result); GC.Collect(); } catch (DialogException dex) { if (dex.Message != DialogException.CanCloseIsFalse) { callback?.Invoke(new DialogResult { Exception = dex, Parameters = parameters }); } } catch (Exception ex) { callback?.Invoke(new DialogResult { Exception = ex, Parameters = parameters }); } } if (closeOnBackgroundTapped) { popupPage.BackgroundClicked += CloseOnBackgroundClicked; } Action <IDialogParameters> closeCallback = closeOnBackgroundTapped ? DialogAware_RequestClose : p => { }; PushPopupPage(popupPage, view, closeCallback, animated); } catch (Exception ex) { callback?.Invoke(new DialogResult { Exception = ex }); } }