private DialogScreenResult ShowModal(IScreenFactory <IScreenBase> screenFactory) { _modal = true; DialogLifecycle dialogLifecycle = null; try { _screen = screenFactory.Create( _aggregator, s => { dialogLifecycle = new DialogLifecycle(s); s.Children.Add(dialogLifecycle); } ); Initialize(); try { _windowService.ShowWindow(_window, modal: true); } catch (Exception ex) { // If an exception is thrown in the UI code of the dialog window (e.g. in // a command handler or on a Dispatcher action), ShowDialog rethrows this // exception but leaves the Window open and visible. if (!ex.IsCritical() && _window.IsVisible) { CloseWindowImmediatately(); } // It's possible that 'HandleClose' or 'HandleWindowClosed' was already executed // but 'ShowDialog' still threw an exception. In that case we have to check the // current state of the screen to prevent invalid state transitions. // TODO: Write a Unit Test when it's known how to reproduce it! CloseScreen(checkState: true); throw; } if (_lastWindowHandlerException != null) { throw _lastWindowHandlerException; } return(dialogLifecycle.ScreenResult ?? new DialogScreenResult(false)); } finally { Disconnect(); if (_screen != null) { _screen .Children .Remove(dialogLifecycle); } if (_window.Owner != null) { // Fix for http://stackoverflow.com/questions/3144004/wpf-app-loses-completely-focus-on-window-close _window.Owner.Activate(); } } }
public TestScreenResult ShowDialog <TScreen>( IScreenFactory <TScreen> screen ) where TScreen : IScreenBase { IScreenBase s = screen.Create(_aggregator); var lifecycle = new DialogLifecycle(s); s.Children.Add(lifecycle); s.Children.Add(new ScreenCloseHandler(_ => { })); // TODO: Remove code duplication between here and responder return(new TestScreenResult(lifecycle)); }
internal TestScreenResult(DialogLifecycle lifecycle) { dialogLifecycle = lifecycle; }