public void Close(Guid windowId, bool removeWindow = true) { var presentationGroupsToClose = this.presentationGroups.FindAll(pg => pg.Window.WindowId == windowId); if (presentationGroupsToClose == null) { throw new ArgumentException($"Window with Id {windowId} not found."); } var setActivePresentation = true; foreach (var presentationGroup in presentationGroupsToClose) { this.RemoveWindowCommandBindings(presentationGroup.ViewModel, presentationGroup.Window); this.RemoveEventHandlers(presentationGroup.ViewModel); (presentationGroup.ViewModel as IDisposable)?.Dispose(); (presentationGroup.View as IDisposable)?.Dispose(); if (removeWindow) { this.presentationGroups.Remove(presentationGroup); if (setActivePresentation) { this.activePresentationGroup = this.oldActivePresentationGroup; this.oldActivePresentationGroup = null; setActivePresentation = false; } } } }
public void ShowInNewWindow <TViewModel>(TViewModel viewModel, Action <TViewModel> viewModelAction = null) where TViewModel : class { var newPresentationGroup = new PresentationGroup(); // show just the first window in the taskbar -> the other ones belong to this one (owner property) newPresentationGroup.Window = new WindowContainer(this) { ShowInTaskbar = !this.presentationGroups.Any() }; if (this.activePresentationGroup != null) { this.oldActivePresentationGroup = this.activePresentationGroup; newPresentationGroup.Window.Owner = this.oldActivePresentationGroup.Window; } else { // powerpoint is owner (first arsnova-integration-window) var ppWindowIntPtr = new IntPtr(Globals.ThisAddIn.Application.ActiveWindow.HWND); var windowCast = new Win32Window(ppWindowIntPtr); var newWindowInteropHelper = new WindowInteropHelper(newPresentationGroup.Window); newWindowInteropHelper.Owner = windowCast.Handle; } var logoBitmap = Images.ARSnova_Logo; var iconBitmapSource = Imaging.CreateBitmapSourceFromHBitmap( logoBitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(16, 16)); newPresentationGroup.Window.Icon = iconBitmapSource; this.presentationGroups.Add(newPresentationGroup); viewModelAction?.Invoke(viewModel); this.Show(viewModel, newPresentationGroup, true); }
public void Show <TViewModel>(TViewModel viewModel) where TViewModel : class { var presentationGroup = this.presentationGroups.FirstOrDefault(vm => vm.ViewModel.GetType() == typeof(TViewModel)); if (presentationGroup != null) { presentationGroup.Window = this.activePresentationGroup.Window; } else { presentationGroup = new PresentationGroup { ViewModel = viewModel, Window = this.activePresentationGroup.Window }; this.presentationGroups.Add(presentationGroup); } // reset window events and bindings (because we want to use the same window again) this.Close(this.activePresentationGroup.Window.WindowId, false); this.Show(viewModel, this.activePresentationGroup); }
private void Show <TViewModel>(TViewModel viewModel, PresentationGroup presentationGroup, bool isNewWindow = false) where TViewModel : class { var viewModelType = typeof(TViewModel); if (!this.viewTypeConfigurations.ContainsKey(viewModelType)) { throw new ArgumentException($"ViewModel not found: '{viewModelType.FullName}'"); } var viewTypeConfiguration = this.viewTypeConfigurations[viewModelType]; // there are currently no view constructors with params -> add option for constructor calls with elements when necessary var view = (Control)viewTypeConfiguration.ViewType.GetConstructors() .FirstOrDefault(c => !c.GetParameters().Any()) .Invoke(new object[0]); view.DataContext = viewModel; this.SetWindowCommandBindings(viewModel, presentationGroup.Window); presentationGroup.Window.Content.Children.Clear(); presentationGroup.Window.Content.Children.Add(view); presentationGroup.ViewModel = viewModel; presentationGroup.View = view; this.activePresentationGroup = presentationGroup; // show -> calling prog doesn't wait (and freezes), showDialog() -> caller waits.... do we want to freeze pp? -> we want to freeze! // side effect: we don't have to handle multiple windows -> the freshly openend one needs to be closed before opening another one (popups doesn't matter) if (isNewWindow) { presentationGroup.Window.ShowDialog(); } }