private void ContentOnRequestClose(IRequestClose item) { item.Guard("item"); IWindowWrapper window; if (!windows.TryGetValue(item, out window)) { return; } window.Close(); windows.Remove(item); }
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { IRequestClose oldViewModel = e.OldValue as IRequestClose; if (oldViewModel != null) { oldViewModel.RequestClose -= this.ViewModelRequestClose; } IRequestClose newViewModel = e.NewValue as IRequestClose; if (newViewModel != null) { newViewModel.RequestClose += this.ViewModelRequestClose; } }
protected RequestCloseWindow() { this.DataContextChanged += this.OnDataContextChanged; this.Closing += (sender, args) => { IRequestClose requestClose = this.DataContext as IRequestClose; if (requestClose != null) { requestClose.WindowClosing(args); // Disconnect the event handler in case the view model is reused. requestClose.RequestClose -= this.ViewModelRequestClose; } }; }
/// <summary> /// Opens the new. /// </summary> /// <param name="content">The content.</param> /// <param name="title">The title.</param> /// <param name="desiredWidth">Width of the desired.</param> /// <param name="desiredHeight">Height of the desired.</param> /// <param name="header">The header.</param> /// <returns></returns> public IWindowWrapper OpenNew(IRequestClose content, string title, int desiredWidth, int desiredHeight, object header = null) { content.Guard("content"); var window = windowFactory.CreateNew(); window.Closing += WindowOnClosing; content.RequestClose += ContentOnRequestClose; window.Content = content; window.Title = title; window.Header = header; window.Width = desiredWidth; window.Height = desiredHeight; windows.Add(content, window); window.Show(); window.Activate(); window.Focus(); return(window); }