private void ClosePopup(IPopupViewModel viewModel) { PopupWindow popup = _Popups.FirstOrDefault(p => ((FrameworkElement)p.Content).DataContext == viewModel); if (popup != null) { _Popups.Remove(popup); if (viewModel.IsModal && _Popups.Count == 0) { EnableMainContentWindow(); } if (_Popups.Count > 0) { _Popups.Last().IsEnabled = true; } popup.ForceClose(); // WORKAROUND: This is here because sometimes when closing a popup, // WPF will minimize the MainWindow even after removing it as owner. // If there's a better way to avoid this, I'm all ears. _MainWindow.Activate(); } }