Class containing a view stack and whether the stack is currently loaded.
예제 #1
0
파일: ViewStack.cs 프로젝트: xaecors/Catel
        /// <summary>
        /// Adds a new child to the stack.
        /// </summary>
        /// <param name="viewStack">The view stack.</param>
        /// <param name="parentViewStack">The parent view stack.</param>
        /// <returns><c>true</c> if added, <c>false</c> otherwise.</returns>
        public bool AddChild(ViewStack viewStack, ViewStack parentViewStack)
        {
            Argument.IsNotNull("viewStack", viewStack);
            Argument.IsNotNull("parentViewStack", parentViewStack);

            if (ReferenceEquals(this, parentViewStack))
            {
                viewStack.ViewStackLoaded   += OnChildViewStackLoaded;
                viewStack.ViewStackUnloaded += OnChildViewStackUnloaded;
                viewStack.ViewLoaded        += OnChildViewLoaded;
                viewStack.ViewUnloaded      += OnChildViewUnloaded;

                _children.Add(viewStack);

                return(true);
            }

            foreach (var child in _children)
            {
                if (child.AddChild(viewStack, parentViewStack))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #2
0
파일: ViewStack.cs 프로젝트: xaecors/Catel
        /// <summary>
        /// Adds a new child to the stack.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <param name="parentViewStack">The parent view stack.</param>
        /// <returns><c>true</c> if added, <c>false</c> otherwise.</returns>
        public bool AddChild(IView view, ViewStack parentViewStack)
        {
            Argument.IsNotNull("view", view);
            Argument.IsNotNull("parentViewStack", parentViewStack);

            var viewStack = new ViewStack(view, false, parentViewStack);

            return(AddChild(viewStack, parentViewStack));
        }
예제 #3
0
파일: ViewStack.cs 프로젝트: xaecors/Catel
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewStack" /> class.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <param name="isViewLoaded">if set to <c>true</c>, the view is loaded.</param>
        /// <param name="parentViewStack">The parent view stack. Can be <c>null</c> for root view stacks.</param>
        private ViewStack(IView view, bool isViewLoaded, ViewStack parentViewStack)
        {
            Argument.IsNotNull("view", view);

            _viewInfo           = new WeakViewInfo(view, isViewLoaded);
            _viewInfo.Loaded   += OnViewLoaded;
            _viewInfo.Unloaded += OnViewUnloaded;

            _parentViewStack = parentViewStack;
            if (parentViewStack != null)
            {
                _parentViewStack.ViewStackLoaded += OnParentViewStackLoaded;
            }
        }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewStack" /> class.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <param name="isViewLoaded">if set to <c>true</c>, the view is loaded.</param>
        /// <param name="parentViewStack">The parent view stack. Can be <c>null</c> for root view stacks.</param>
        private ViewStack(IView view, bool isViewLoaded, ViewStack parentViewStack)
        {
            Argument.IsNotNull("view", view);

            _viewInfo = new WeakViewInfo(view, isViewLoaded);
            _viewInfo.Loaded += OnViewLoaded;
            _viewInfo.Unloaded += OnViewUnloaded;

            _parentViewStack = parentViewStack;
            if (parentViewStack != null)
            {
                _parentViewStack.ViewStackLoaded += OnParentViewStackLoaded;
            }
        }
예제 #5
0
            public UninitializedViewInfo(IViewLoadState viewLoadState)
            {
                ViewLoadState = viewLoadState;

                ViewStack = new ViewStack(viewLoadState.View, false);
            }
예제 #6
0
        /// <summary>
        /// Adds a new child to the stack.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <param name="parentViewStack">The parent view stack.</param>
        /// <returns><c>true</c> if added, <c>false</c> otherwise.</returns>
        public bool AddChild(IView view, ViewStack parentViewStack)
        {
            Argument.IsNotNull("view", view);
            Argument.IsNotNull("parentViewStack", parentViewStack);

            var viewStack = new ViewStack(view, false, parentViewStack);

            return AddChild(viewStack, parentViewStack);
        }
예제 #7
0
        /// <summary>
        /// Adds a new child to the stack.
        /// </summary>
        /// <param name="viewStack">The view stack.</param>
        /// <param name="parentViewStack">The parent view stack.</param>
        /// <returns><c>true</c> if added, <c>false</c> otherwise.</returns>
        public bool AddChild(ViewStack viewStack, ViewStack parentViewStack)
        {
            Argument.IsNotNull("viewStack", viewStack);
            Argument.IsNotNull("parentViewStack", parentViewStack);

            if (ReferenceEquals(this, parentViewStack))
            {
                viewStack.ViewStackLoaded += OnChildViewStackLoaded;
                viewStack.ViewStackUnloaded += OnChildViewStackUnloaded;
                viewStack.ViewLoaded += OnChildViewLoaded;
                viewStack.ViewUnloaded += OnChildViewUnloaded;

                _children.Add(viewStack);

                return true;
            }

            foreach (var child in _children)
            {
                if (child.AddChild(viewStack, parentViewStack))
                {
                    return true;
                }
            }

            return false;
        }
예제 #8
0
            public UninitializedViewInfo(IViewLoadState viewLoadState)
            {
                ViewLoadState = viewLoadState;

                ViewStack = new ViewStack(viewLoadState.View, false);
            }
예제 #9
0
        private void AddViewAfterLoaded(UninitializedViewInfo uninitializedViewInfo)
        {
            var isTopViewStack = true;

            var       viewLoadState = uninitializedViewInfo.ViewLoadState;
            var       view          = viewLoadState.View;
            ViewStack viewStack     = null;

            var parent = view.FindParentByPredicate(x => x is IView) as FrameworkElement;

            if (parent != null)
            {
                if (_uninitializedViews.ContainsKey(parent))
                {
                    // We have a different uninitialized view that is the parent
                    var uninitializedParent = _uninitializedViews[parent];
                    uninitializedParent.ViewStack.AddChild(uninitializedViewInfo.ViewStack, uninitializedParent.ViewStack);

                    isTopViewStack = false;
                }
                else
                {
                    // We are now listed to be added to the visual tree
                    foreach (var existingViewStack in _viewStacks)
                    {
                        if (existingViewStack.ContainsView((IView)parent))
                        {
                            var viewAsFrameworkElement = view as FrameworkElement;
                            if (viewAsFrameworkElement != null && _uninitializedViews.ContainsKey(viewAsFrameworkElement))
                            {
                                // This happens when we are called from OnFrameworkElementLoaded but out parent wasn't updated yet
                                existingViewStack.AddChild(_uninitializedViews[viewAsFrameworkElement].ViewStack, existingViewStack);
                            }
                            else
                            {
                                existingViewStack.AddChild(view, existingViewStack);
                            }


                            viewStack      = existingViewStack;
                            isTopViewStack = false;
                            break;
                        }
                    }
                }
            }

            if (isTopViewStack)
            {
                var topViewStack = uninitializedViewInfo.ViewStack;

                topViewStack.ViewStackLoaded   += OnViewStackLoaded;
                topViewStack.ViewStackUnloaded += OnViewStackUnloaded;

                _viewStacks.Add(topViewStack);

                viewStack = topViewStack;
            }

            if (viewStack != null)
            {
                viewStack.NotifyThatParentIsReadyToAcceptLoadedMessages();
            }
        }