public void Show(PopupItem item) { if (item == null) { throw new ArgumentNullException(nameof(item)); } if (this.VerifyIsMessageDialogBox(item)) { throw new InvalidOperationException($"视图类型 {typeof(MessageDialogBox)} 必须以模态方式进行显示。"); } //堆栈最上层若是模态窗口,则不予显示当前窗口,并激活最上层的模态窗口 if (this.VerifyTopItemModal()) { if (!this.VerifyIsProcessDialogBox(item)) { PopupItemContainer container = this.PopupContainerFromIndex(this._popupStack.Items.Count - 1); if (container != null) { container.Flicker(); } return; } } if (this.Contains(item)) { this.MoveItemToTop(item); } else { this.VerifyCanShow(item); item._isShowing = true; CancelEventArgs ce = null; try { item.InternalShowing(out ce); } catch (Exception) { item._isShowing = false; throw; } if (!ce.Cancel) { this.ShowCore(item); } } }
public ModalResult ShowModal(PopupItem item) { if (item == null) { throw new ArgumentNullException(nameof(item)); } if (this.VerifyIsProcessDialogBox(item)) { throw new InvalidOperationException($"视图类型 {typeof(ProcessDialogBox)} 不可以模态方式进行显示。"); } //以模态显示窗口时,若发现最上层是模态窗口 //当顶级窗口为MessageDialogBox时不予显示当前窗口 //当顶级窗口不是MessageDialogBox时,若当前为MessageDialogBox,则显示 if (this.VerifyTopItemModal()) { if (this.VerifyTopItemIsMessageDialogBox() || !this.VerifyIsMessageDialogBox(item)) { PopupItemContainer container = this.PopupContainerFromIndex(this._popupStack.Items.Count - 1); if (container != null) { container.Flicker(); } return(null); } } this.VerifyCanShow(item); item._isShowing = true; item._showingAsModal = true; item._modalResult = null; CancelEventArgs ce = null; try { item.InternalShowing(out ce); } catch (Exception) { //状态还原 item._isShowing = false; item._showingAsModal = false; throw; } bool notcanceled = !ce.Cancel; try { if (notcanceled) { ComponentDispatcher.PushModal(); item._dispatcherFrame = new DispatcherFrame(); try { this.ShowCore(item); } finally { //确保Shown事件异常时,Modal的结果不受影响 Dispatcher.PushFrame(item._dispatcherFrame); } return(item.ModalResult); } } finally { //确保ComponentDispatcher有进有出 if (notcanceled) { ComponentDispatcher.PopModal(); } } return(null); }
public ModalResult ShowModal(PopupItem item) { if (item == null) { throw new ArgumentNullException(nameof(item)); } if (this.VerifyIsProcessDialogBox(item)) { throw new Exception($"视图类型 {typeof(ProcessDialogBox)} 不可以模态方式进行显示。"); } //以模态显示窗口时,若发现最上层是模态窗口 //当顶级窗口为MessageDialogBox时不予显示当前窗口 //当顶级窗口不是MessageDialogBox时,若当前为MessageDialogBox,则显示 if (this.VerifyTopItemModal()) { if (this.VerifyTopItemIsMessageDialogBox() || !this.VerifyIsMessageDialogBox(item)) { PopupItemContainer container = this.PopupContainerFromIndex(this._popupStack.Items.Count - 1); if (container != null) { container.Flicker(); } return(null); } } item.VerifyCanShow(this); item._showingAsModal = true; item._modalResult = null; CancelEventArgs ce = null; try { item.InternalShowing(out ce); } catch (Exception) { item._showingAsModal = false; throw; } try { if (!ce.Cancel) { ComponentDispatcher.PushModal(); item._dispatcherFrame = new DispatcherFrame(); item.ParentHostStack = this; item._isClosed = false; this.AddItem(item); item.InternalShown(out EventArgs e); Dispatcher.PushFrame(item._dispatcherFrame); return(item.ModalResult); } } finally { ComponentDispatcher.PopModal(); item.InternalDiapose(); } return(null); }