public async ValueTask <T> ShowDialogAsync <T>(DialogScreen <T> dialogScreen) { var view = _viewManager.CreateAndBindViewForModelIfNecessary(dialogScreen); void OnDialogOpened(object?sender, DialogOpenedEventArgs openArgs) { void OnScreenClosed(object?o, EventArgs closeArgs) { openArgs.Session.Close(); dialogScreen.Closed -= OnScreenClosed; } dialogScreen.Closed += OnScreenClosed; } await DialogHost.Show(view, OnDialogOpened); return(dialogScreen.DialogResult); }
public async Task <T> ShowDialogAsync <T>(DialogScreen <T> dialogScreen) { // Get the view that renders this viewmodel var view = _viewManager.CreateAndBindViewForModelIfNecessary(dialogScreen); // Set up event routing that will close the view when called from viewmodel void OnDialogOpened(object?sender, DialogOpenedEventArgs openArgs) { // Delegate to close the dialog and unregister event handler void OnScreenClosed(object?o, EventArgs closeArgs) { openArgs.Session.Close(); dialogScreen.Closed -= OnScreenClosed; } dialogScreen.Closed += OnScreenClosed; } // Show view await DialogHost.Show(view, OnDialogOpened); // Return the result return(dialogScreen.DialogResult); }