private bool CheckAtSwitch(PopupItem item)
 {
     //目前在其它视图栈,检查是否处在从其它视图栈移动视图模式
     return(item._isHostAtViewStack &&
            item.ParentHostStack != null &&
            !object.ReferenceEquals(this, item.ParentHostStack));
 }
예제 #2
0
        public void Show(PopupItem item)
        {
            this.VerifyCanAsParent(item);
            item.ParentPopup = this;

            this._popupStackControl.Show(item);
        }
        private void RemoveItem(PopupItem item)
        {
            var container = this.PopupContainerFromItem(item);

            this._popupStack.Items.Remove(container);
            item._isHostAtViewStack = false;
        }
        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);
            }
        }
예제 #5
0
        public ModalResult ShowModal(PopupItem item)
        {
            this.VerifyCanAsParent(item);
            item.ParentPopup = this;

            return(this._popupStackControl.ShowModal(item));
        }
        internal void VerifyCanShow(PopupItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            //当前是独立作为视图栈
            if (this._parentPopupItem == null)
            {
                if (item._isClosing)
                {
                    throw new InvalidOperationException("该项当前不可显示,因为它当前正在关闭");
                }

                if (item._isShowing)
                {
                    throw new InvalidOperationException("该项当前不可显示,因为它当前正在显示");
                }

                if (item._showingAsModal)
                {
                    throw new InvalidOperationException("该项当前不可显示,因为它当前正在以模态显示");
                }

                if (item._isHostAtViewStack)
                {
                    throw new InvalidOperationException("该项当前不可显示,因为它当前正在其它视图堆栈中显示");
                }
            }
            else
            {
                //PopupItem 中的视图栈
                if (this.VerifyIsSpecialItem(this._parentPopupItem))
                {
                    throw new InvalidOperationException($"不可在 {typeof(MessageDialogBox)}、{typeof(ProcessDialogBox)} 等特殊视图中显示子视图");
                }

                if (object.ReferenceEquals(this._parentPopupItem, item))
                {
                    throw new InvalidOperationException("不可在自己的视图堆栈中显示自己");
                }

                if (this._parentPopupItem._isClosing)
                {
                    throw new InvalidOperationException("该项当前不可做为容器去显示其它PopupItem,因为它当前正在关闭");
                }

                if (!this._parentPopupItem._isHostAtViewStack)
                {
                    throw new InvalidOperationException("该项当前不可做为容器去显示其它PopupItem,因为它当前未显示");
                }

                if (this._parentPopupItem._showingAsModal)
                {
                    throw new InvalidOperationException("该项当前不可做为容器去显示其它PopupItem,因为它当前正在以模态显示");
                }
            }
        }
        private void AddItem(PopupItem item)
        {
            PopupItemContainer container = item.GetContainer();

            container.PopupItem = item;
            this._popupStack.Items.Add(container);
            item._isHostAtViewStack = true;
        }
예제 #8
0
        public ModalResult ShowModal(PopupItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            return(this._childPopupStackControl.ShowModal(item));
        }
예제 #9
0
        public void Show(PopupItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            this._childPopupStackControl.Show(item);
        }
예제 #10
0
        internal PopupStackControl(PopupItem popupItem)
            : this()
        {
            if (popupItem == null)
            {
                throw new ArgumentNullException(nameof(popupItem));
            }

            this._parentPopupItem = popupItem;
        }
예제 #11
0
        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);
     }
 }
예제 #13
0
        public PopupItemContainer PopupContainerFromItem(PopupItem item)
        {
            foreach (PopupItemContainer container in this._popupStack.Items)
            {
                if (object.ReferenceEquals(container.PopupItem, item))
                {
                    return(container);
                }
            }

            return(null);
        }
예제 #14
0
        public bool Contains(PopupItem item)
        {
            foreach (PopupItemContainer container in this._popupStack.Items)
            {
                if (object.ReferenceEquals(container.PopupItem, item))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #15
0
        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;
        }
예제 #16
0
 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);
            }
        }
예제 #18
0
        internal void VerifyCanAsParent(PopupItem item)
        {
            if (object.ReferenceEquals(this, item))
            {
                throw new Exception("项不能在自己的视图堆栈中显示");
            }

            if (this._isClosing)
            {
                throw new Exception("该项当前不可做为容器去显示其它PopupItem,因为它当前正在关闭");
            }

            if (this._isClosed)
            {
                throw new Exception("该项当前不可做为容器去显示其它PopupItem,因为它当前已关闭");
            }

            if (this._showingAsModal)
            {
                throw new Exception("该项当前不可做为容器去显示其它PopupItem,因为它当前正在以模态显示");
            }
        }
예제 #19
0
 public void Show(PopupItem item)
 {
     this._popupStackControl.Show(item);
 }
 public void Show(PopupItem item)
 {
     this._richViewControl.Show(item);
 }
예제 #21
0
        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)
 {
     this._richViewControl.Close(item);
 }
예제 #23
0
        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 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;
            }
        }
예제 #25
0
 public ModalResult ShowModal(PopupItem item)
 {
     return(this._popupStackControl.ShowModal(item));
 }
예제 #26
0
 public void Close(PopupItem item)
 {
     this._popupStackControl.Close(item);
 }
예제 #27
0
 private bool VerifyIsMessageDialogBox(PopupItem item)
 {
     return(item is MessageDialogBox);
 }
 public ModalResult ShowModal(PopupItem item)
 {
     return(this._richViewControl.ShowModal(item));
 }
예제 #29
0
 private bool VerifyIsSpecialItem(PopupItem item)
 {
     return(item is MessageDialogBox ||
            item is ProcessDialogBox);
 }
예제 #30
0
 private bool VerifyIsProcessDialogBox(PopupItem item)
 {
     return(item is ProcessDialogBox);
 }