private void ShowCore(PopupItem item)
        {
            item.ParentHostStack = this;
            try
            {
                this.AddItem(item);
            }
            finally
            {
                item._isShowing = false;
            }

            if (ViewPreferences.Instance.UsePopupViewAnimations)
            {
                PopupItemContainer itemContainer = this.PopupContainerFromItem(item);
                itemContainer.RequestShowAnimation(_p =>
                {
                    //若不使用InvokeAsync调度,某些情况可能会出现页面不绘制问题
                    this.Dispatcher.InvokeAsync(() =>
                    {
                        item.InternalShown(out EventArgs e);
                    }, DispatcherPriority.Send);
                });
            }
            else
            {
                item.InternalShown(out EventArgs e);
            }
        }
        private void AddItem(PopupItem item)
        {
            PopupItemContainer container = item.GetContainer();

            container.PopupItem = item;
            this._popupStack.Items.Add(container);
            item._isHostAtViewStack = true;
        }
        private void TopFlicker()
        {
            PopupItemContainer container = this.PopupContainerFromIndex(this._popupStack.Items.Count - 1);

            if (container != null)
            {
                container.Flicker();
            }
        }
        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);
                }
            }
        }
 private void MoveItemToTop(PopupItem item)
 {
     if (this.Contains(item) &&
         !object.ReferenceEquals(this.TopItem, item))
     {
         PopupItemContainer container = this.PopupContainerFromItem(item);
         this._popupStack.Items.Remove(container);
         this._popupStack.Items.Add(container);
         container.OnShowAnimation(null);
     }
 }
        private void AddItem(PopupItem item)
        {
            PopupItemContainer container = item.GetContainer();

            if (container == null)
            {
                container = new DefaultPopupItemContainer();
            }
            container.PopupItem = item;
            this._popupStack.Items.Add(container);
            item._isHostAtViewStack = true;
            item.ParentPopup        = this._parentPopupItem;
        }
 private void MoveItemToTop(PopupItem item)
 {
     if (this.Contains(item) &&
         !object.ReferenceEquals(this.TopItem, item))
     {
         PopupItemContainer container = this.PopupContainerFromItem(item);
         this._popupStack.Items.Remove(container);
         this._popupStack.Items.Add(container);
         if (ViewPreferences.Instance.UsePopupViewAnimations)
         {
             container.RequestShowAnimation(null);
         }
     }
 }
        public void Show(PopupItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            if (this.VerifyIsMessageDialogBox(item))
            {
                throw new Exception($"视图类型 {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))
            {
                item.VerifyCanShow(this);

                item.InternalShowing(out CancelEventArgs ce);
                if (!ce.Cancel)
                {
                    item._isClosed       = false;
                    item.ParentHostStack = this;
                    this.AddItem(item);
                    item.InternalShown(out EventArgs e);
                }
            }
            else
            {
                this.MoveItemToTop(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);
        }