public bool?ShowDialog <TViewModel>(TViewModel viewModel) where TViewModel : IGameWindowRequestClose { Type viewType = Mappings[typeof(TViewModel)]; IGameWindow gameWindow = (IGameWindow)Activator.CreateInstance(viewType); EventHandler <GameWindowCloseRequestedEventArgs> handler = null; handler = (sender, e) => { viewModel.CloseRequested -= handler; if (e.DialogResult.HasValue) { gameWindow.DialogResult = e.DialogResult; } else { gameWindow.Close(); } }; viewModel.CloseRequested += handler; gameWindow.DataContext = viewModel; gameWindow.Owner = _owner; return(gameWindow.ShowDialog()); }