private static void OnViewClosing(object sender, CancelEventArgs e) { View = null; if (sender is CreateModelView view) { view.Closing -= OnViewClosing; } _logger.Info("Create Model ended."); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { _logger.Info("Create Model started."); var uiApp = commandData.Application; var uiDoc = uiApp.ActiveUIDocument; if (View != null) { if (View.WindowState == WindowState.Minimized) { View.WindowState = WindowState.Normal; } View.Activate(); return(Result.Succeeded); } var m = new CreateModelModel(uiDoc); var vm = new CreateModelViewModel(m, false); var v = new CreateModelView { DataContext = vm }; View = v; View.Closing += OnViewClosing; var unused = new WindowInteropHelper(v) { Owner = Process.GetCurrentProcess().MainWindowHandle }; v.Show(); _logger.Info("Create Model ended."); return(Result.Succeeded); } catch (Exception e) { _logger.Fatal(e); return(Result.Failed); } }