/// <summary> /// This method closes all currently open views /// </summary> /// <returns>True if the handler successfully closed all views. False if it didn't close all views or generally does not handle view closing</returns> /// <exception cref="System.NotImplementedException"></exception> public bool CloseAllViews() { var topLevelViews = TopLevelViews.ToArray(); foreach (var view in topLevelViews) { TopLevelViews.Remove(view); if (view.TopLevelWindow != null) { view.TopLevelWindow.Close(); } view.RaiseViewClosed(); } SelectedTopLevelView = -1; SelectedTopLevelViewResult = null; TopLevelViewCount = 0; var normalViews = NormalViews.ToArray(); foreach (var view in normalViews) { NormalViews.Remove(view); if (view.TopLevelWindow != null) { view.TopLevelWindow.Close(); } view.RaiseViewClosed(); } SelectedNormalView = -1; SelectedNormalViewResult = null; NormalViewCount = 0; return(true); }
/// <summary> /// This method is invoked when a view that is associated with a certain model should be closed /// </summary> /// <param name="model"></param> /// <returns></returns> public bool CloseViewForModel(object model) { foreach (var view in TopLevelViews) { if (view.Model != null && view.Model == model) { TopLevelViews.Remove(view); SelectedTopLevelView = TopLevelViews.Count - 1; SelectedTopLevelViewResult = SelectedTopLevelView > -1 ? TopLevelViews[SelectedTopLevelView] : null; TopLevelViewCount = TopLevelViews.Count; if (view.TopLevelWindow != null) { view.TopLevelWindow.Close(); } view.RaiseViewClosed(); return(true); } } foreach (var view in NormalViews) { if (view.Model != null && view.Model == model) { NormalViews.Remove(view); SelectedNormalView = NormalViews.Count - 1; SelectedNormalViewResult = SelectedNormalView > -1 ? NormalViews[SelectedNormalView] : null; NormalViewCount = NormalViews.Count; if (view.TopLevelWindow != null) { view.TopLevelWindow.Close(); } view.RaiseViewClosed(); return(true); } foreach (var localView in view.LocalViews) { if (localView.Model != null && localView.Model == model) { view.LocalViews.Remove(localView); if (view.SelectedLocalViewIndex >= view.LocalViews.Count) { view.SelectedLocalViewIndex = view.LocalViews.Count - 1; } localView.RaiseViewClosed(); return(true); } } } return(false); }