public void Close(PopupItem item) { if (item == null) { return; } if (item._isClosing || !item._isHostAtViewStack) { return; } if (!this.Contains(item)) { throw new InvalidOperationException("该项当前不可关闭,因为它不处于当前的视图栈"); } item._isClosing = true; CancelEventArgs ce = null; try { item.InternalClosing(out ce); } catch (Exception) { item._isClosing = false; throw; } void CloseAndDisposeItem(PopupItem popupItem) { this.RemoveItem(popupItem); popupItem._isClosing = false; try { popupItem.InternalClosed(out EventArgs e); } finally { popupItem.InternalDiapose(); } } //若所属父视图堆栈已关闭,不验证关于取消关闭的操作 if (item.ParentPopup?._isHostAtViewStack == false) { CloseAndDisposeItem(item); } else if (!ce.Cancel) { if (ViewPreferences.Instance.UsePopupViewAnimations) { var container = this.PopupContainerFromItem(item); container.OnCloseAnimation(_p => { //若不使用InvokeAsync调度,某些情况可能会出现页面不绘制问题 this.Dispatcher.InvokeAsync(() => { CloseAndDisposeItem(item); }, DispatcherPriority.Send); }); } else { CloseAndDisposeItem(item); } } else { item._isClosing = false; } }
public void Close(PopupItem item) { if (item == null) { return; } if (item._isClosing || item._isClosed) { return; } if (!this.Contains(item)) { throw new Exception("该项当前不可关闭,因为它不处于当前的试图堆栈"); } item._isClosing = true; CancelEventArgs ce = null; try { item.InternalClosing(out ce); } catch (Exception) { item._isClosing = false; throw; } void CloseAndDisposeItem(PopupItem popupItem) { this.RemoveItem(popupItem); try { popupItem.InternalClosed(out EventArgs e); } finally { popupItem.InternalDiapose(); } } //若所属父视图堆栈已关闭 if (item.ParentPopup?._isClosed == true) { CloseAndDisposeItem(item); } else if (!ce.Cancel) { var container = this.PopupContainerFromItem(item); container.OnCloseAnimation(_p => { CloseAndDisposeItem(item); }); } else { item._isClosing = false; } }