public void Show(IWindowViewModel vm) { if (GetView(vm) is Window window) { window.Show(); } }
private void ShowWindowDialog_Closed(object a_sender, EventArgs a_e) { Window window = (Window)a_sender; IWindowViewModel viewModel = (IWindowViewModel)window.DataContext; viewModel.WindowClosed(); viewModel.WindowView = null; window.Closing -= ShowWindowDialog_Closing; window.Closed -= ShowWindowDialog_Closed; Action closeAction = window.Tag as Action; if (closeAction != null) { closeAction(); window.Tag = null; } // Remove the VM. IViewFor viewFor = window as IViewFor; if (viewFor != null) { viewFor.ViewModel = null; } }
/// <inheritdoc /> public async Task <bool> OpenWindowAsync(IWindowViewModel viewModel, string windowId) { var coordinator = CoordinatorFactory.Create(viewModel); Log.Debug($"Opening window {viewModel.GetType().FullName}"); return(await coordinator.DisplayAsync(viewModel, new WindowArguments(windowId ?? Guid.NewGuid().ToString()))); }
public void ShowDialog(IWindowViewModel viewModel, ResizeMode resizeMode) { viewModel.Closed = false; ClosableWindow window = CreateWindow(viewModel, resizeMode); window.OpenDialog(); }
public void Show(IWindowViewModel windowViewModel) { if (windowViewModel == null) { throw new ArgumentNullException(nameof(windowViewModel)); } CreateWindow(windowViewModel).Show(); }
private Window CreateWindow(IWindowViewModel windowViewModel) { var window = (Window)Activator.CreateInstance(m_viewMapping[windowViewModel.GetType()]); window.DataContext = windowViewModel; window.Loaded += (sender, args) => windowViewModel.OnViewIsLoaded(); window.Closed += (sender, args) => windowViewModel.OnViewIsClosed(); return(window); }
public bool?OpenDialog(IWindowViewModel viewModel, bool allowResize, double?width, double?height) { Window window = CreateWindow(viewModel, allowResize, width, height); // Do not show dialog in taskbar window.ShowInTaskbar = false; // Register KeyDown event window.PreviewKeyDown += Window_PreviewKeyDown; // Show window return(window.ShowDialog()); }
public void CloseWindow(IWindowViewModel viewModel, bool result) { Window window = _openWindows.FirstOrDefault(w => w.DataContext == viewModel); if (window != null) { //window.Close(); window.DialogResult = result; _openWindows.Remove(window); } }
private void ShowWindowDialog_Closing(object a_sender, CancelEventArgs a_e) { Window window = (Window)a_sender; IWindowViewModel viewModel = window.DataContext as IWindowViewModel; if (viewModel == null) { return; } a_e.Cancel = !viewModel.WindowIsClosing(); }
public Task <TResult> ShowDialog <TResult>(IWindowViewModel vm) { if (GetView(vm) is Window window) { Window owner = LightApplicationBase.MainWindow ?? window; if (owner != window) { return(window.ShowDialog <TResult>(owner)); } } return(null); }
/// <summary> /// Creates a WPF Window object with an attached ViewModel. Offers the option to enable/disable event handlers. /// </summary> /// <param name="window">The XAML markup object the viewmodel is to be mapped to.</param> /// <param name="windowViewModel">The object assigned to the window as a ViewModel.</param> /// <param name="hasEventHandlers">Indicates whether or not the ViewModel has control over window state.</param> public WindowInitializer(Window window, IWindowViewModel windowViewModel, bool hasEventHandlers) { _window = window; _windowViewModel = windowViewModel; if (hasEventHandlers) { _windowViewModel.PropertyChanged += windowViewModel_PropertyChanged; } window.DataContext = _windowViewModel; }
private Window CreateWindow(IWindowViewModel viewModel, bool allowResize, double?width, double?height) { Window window = new Window(); try { window.Owner = Application.Current.MainWindow; window.WindowStartupLocation = WindowStartupLocation.CenterScreen; } catch { window.WindowStartupLocation = WindowStartupLocation.CenterScreen; } window.ResizeMode = allowResize ? ResizeMode.CanResizeWithGrip : ResizeMode.NoResize; window.WindowStyle = WindowStyle.SingleBorderWindow; window.ShowInTaskbar = true; if (width != null && height != null) { window.SizeToContent = SizeToContent.Manual; window.Width = width.Value; window.Height = height.Value; } else { window.SizeToContent = SizeToContent.WidthAndHeight; } window.Content = viewModel; window.DataContext = viewModel; window.ResizeMode = allowResize ? ResizeMode.CanResizeWithGrip : ResizeMode.NoResize; // Bind window title if (string.IsNullOrEmpty(window.Title)) { window.SetBinding(Window.TitleProperty, nameof(IWindowViewModel.DisplayName)); } // The WindowManager will always live longer than the window, // so we don't need to unsubscribe this event handler. window.Closed += Window_Closed; // Add to open windows _openWindows.Add(window); return(window); }
private void ShowWindow(IViewModel a_ownerViewModel, IWindowViewModel a_viewModel, Window a_dialog, Action a_windowClosedCallback) { // Create dialog and set properties a_dialog.DataContext = a_viewModel; a_dialog.Owner = a_ownerViewModel != null?FindOwnerWindow(a_ownerViewModel) : null; // Bind the closing event to the viewmodel. a_dialog.Closing += ShowWindowDialog_Closing; a_dialog.Closed += ShowWindowDialog_Closed; a_dialog.Tag = a_windowClosedCallback; a_viewModel.WindowView = a_dialog as IWindowView; // Show dialog a_dialog.Show(); }
public void Close(IWindowViewModel vm) { if (GetView(vm) is Window window) { // remove view first viewStore.Remove(vm); if (vm.DialogResult != null) { window.Close(vm.DialogResult); } else { window.Close(); } } }
private ClosableWindow CreateWindow(IWindowViewModel viewModel, ResizeMode resizeMode) { System.Windows.ResizeMode mode = GetMode(resizeMode); var window = new ClosableWindow(viewModel, mode); if (ownerWindow != null) { window.Owner = ownerWindow; window.WindowStartupLocation = WindowStartupLocation.CenterOwner; } else if (ownerForm != null) { var helper = new WindowInteropHelper(window); helper.Owner = ownerForm.Handle; window.WindowStartupLocation = WindowStartupLocation.CenterOwner; } return(window); }
private void ShowWindow(IWindowViewModel vm, Window w, bool setOwner) { if (setOwner) { w.Owner = this; } w.DataContext = vm; w.Closed += (s, e) => { vm.IsClosed = true; }; var path = new PropertyPath(typeof(IWindowViewModel).GetProperty("IsActive")); w.SetBinding(ActivateBehavior.IsActiveProperty, new Binding() { Path = path }); w.Show(); }
public void SetSizeAndPosition(IWindowViewModel viewModel, Rect rect) { Window window = m_views.First(n => ReferenceEquals(n.DataContext, viewModel)) as Window; if (window == null) return; window.Left = rect.X; window.Top = rect.Y; window.Width = rect.Width; window.Height = rect.Height; }
public void OpenWindow(IWindowViewModel viewModel, bool allowResize, double?width, double?height) { Window window = CreateWindow(viewModel, allowResize, width, height); window.Show(); }
/// <summary> /// Creates a WPF Window object with an attached ViewModel. /// </summary> /// <param name="window">The XAML markup object the viewmodel is to be mapped to.</param> /// <param name="windowViewModel">The object assigned to the window as a ViewModel.</param> public WindowInitializer(Window window, IWindowViewModel windowViewModel) : this(window, windowViewModel, true) { }
public void CloseWindow(IWindowViewModel viewModel) { CloseWindow(viewModel, true); }
public void OpenWindow(IWindowViewModel viewModel, bool allowResize) { }
public void OpenWindow(IWindowViewModel viewModel, bool allowResize, double?width, double?height) { }
public Rect GetSizeAndPosition(IWindowViewModel viewModel) { Window window = m_views.First(n => ReferenceEquals(n.DataContext, viewModel)) as Window; if (window == null) return default(Rect); return new Rect(window.Left, window.Top, window.Width, window.Height); }
public void OpenWindow(IWindowViewModel viewModel) { }
public bool?OpenDialog(IWindowViewModel viewModel, bool allowResize) { return(OpenDialog(viewModel, allowResize, null, null)); }
public void CloseDialog(IWindowViewModel viewModel) { List<FrameworkElement> windowsToClose = m_views.Where(n => ReferenceEquals(n.DataContext, viewModel)).ToList(); foreach (Window window in windowsToClose) { window.Close(); } }
public void OpenWindow(IWindowViewModel viewModel) { OpenWindow(viewModel, true); }
public ApplicationViewModel(IWindowViewModel window, NavigationViewModel router) { Window = window; Router = router; Router.OnNavigated += Router_OnNavigated; }
public void ShowWindow(IWindowViewModel viewModel, Rect? rect = null) { if (!m_rootView.View.Dispatcher.CheckAccess()) { m_rootView.View.Dispatcher.Invoke(() => ShowWindow(viewModel, rect)); return; } Window dialog = Activator.CreateInstance(viewModel.WindowsType) as Window; if (dialog == null) throw new ArgumentException("viewType must be of type Window"); dialog.DataContext = viewModel; Register(dialog); if (rect != null) SetSizeAndPosition(viewModel, (Rect)rect); dialog.Show(); }
public void OpenWindow(IWindowViewModel viewModel, bool allowResize) { OpenWindow(viewModel, allowResize, null, null); }
public bool?OpenDialog(IWindowViewModel viewModel) => false;
public bool?OpenDialog(IWindowViewModel viewModel) { return(OpenDialog(viewModel, true)); }
public bool?OpenDialog(IWindowViewModel viewModel, bool allowResize) => false;
public bool?OpenDialog(IWindowViewModel viewModel, bool allowResize, double?width, double?height) => false;
public void BringToFront(IWindowViewModel viewModel) { Application.Current.Dispatcher.Invoke(() => BringToFront(FindOwner(viewModel))); }
public ApplicationViewModel(IWindowViewModel window, NavigationViewModel router) { Window = window; Router = router; }
public void CloseWindow(IWindowViewModel viewModel, bool result) { }