예제 #1
0
        public ViewBackstackEntry ToBackstack()
        {
            ViewBackstackEntry newEntry = null;

            if (data.ShouldGoToBackStack)
            {
                newEntry = new ViewBackstackEntry();

                newEntry.ViewID              = ViewID;
                newEntry.ApplicationID       = ApplicationID;
                newEntry.URI                 = URI;
                newEntry.CacheID             = CacheID;
                newEntry.Transition          = data.Transition;
                newEntry.IsPopup             = data.IsPopup;
                newEntry.WasCached           = data.WasCached;
                newEntry.ShouldGoToBackStack = data.ShouldGoToBackStack;
                newEntry.DefinitionID        = (data.Root != null) ? data.Root.DefinitionID : -1;
                newEntry.SignpostNames       = data.SignpostNames;

                newEntry.LiveEntity = this;
            }

            return(newEntry);
        }
예제 #2
0
        private bool ShowPreviousNode()
        {
            // save current node
            Node currentNode = CurrentNode;

            // search for backstack entry
            ViewBackstackEntry entry = null;

            if (backstack.Count > 0)
            {
                entry = backstack.Pop();
            }

            if (entry != null)
            {
                // have old node - restore it
                Node prevNode = entry.LiveEntity;

                if (prevNode == null)
                {
                    prevNode = CreateNewNode(entry.ToNodeData());

                    if (prevNode != null)
                    {
                        Children.Add(prevNode);
                    }
                }

                if (prevNode != null)
                {
                    // deactivate current node (if any)
                    if (currentNode != null)
                    {
                        currentNode.SignalHide();
                    }

                    // show restored node and activate it
                    prevNode.Visibility = Visibility.Visible;
                    prevNode.SignalShow();

                    // launch transition
                    TransitionHelper.Hide(
                        currentNode,
                        currentNode.Transition,
                        () =>
                    {
                        if (currentNode != null)
                        {
                            // hide
                            currentNode.Visibility = Visibility.Collapsed;

                            // destroy
                            Children.Remove(currentNode);

                            currentNode.SignalDestroy();
                            currentNode = null;
                        }
                    });

                    return(true);
                }
            }
            else
            {
                // backstack is empty - just deactivate current node
                if (currentNode != null)
                {
                    currentNode.SignalHide();
                    currentNode.SignalDestroy();
                    currentNode = null;
                }
            }

            return(false);
        }
예제 #3
0
        private void ShowNewNode(Node newNode)
        {
            if (newNode != null)
            {
                Node currentNode = CurrentNode;
                bool hideOldNode = true, destroyOldNode = false;

                // handle current node
                if (currentNode != null)
                {
                    ViewBackstackEntry newEntry = null;

                    if (isBackstackEnabled)
                    {
                        newEntry = currentNode.ToBackstack();
                    }

                    // method ToBackstack() returns null if the current node should not be added to backstack
                    if (newEntry != null)
                    {
                        // save current node to backstack
                        backstack.Push(newEntry);

                        // clean backstack (if needed)
                        if (backstack.Count > BackstackLiveEntitiesLimit)
                        {
                            var backstackEntries = backstack.ToArray();

                            for (int i = BackstackLiveEntitiesLimit; i < backstackEntries.Length; i++)
                            {
                                if (backstackEntries[i].LiveEntity != null)
                                {
                                    backstackEntries[i].LiveEntity.Visibility = Visibility.Collapsed;

                                    Children.Remove(backstackEntries[i].LiveEntity);
                                    backstackEntries[i].LiveEntity = null;
                                }
                            }
                        }

                        // set actions
                        hideOldNode    = !newNode.IsPopup;
                        destroyOldNode = false;
                    }
                    else
                    {
                        // must hide and destroy old node
                        hideOldNode    = true;
                        destroyOldNode = true;
                    }
                }

                // handle new node
                Children.Add(newNode);

                // launch transition
                TransitionHelper.Show(
                    newNode,
                    newNode.Transition,
                    () =>
                {
                    if (currentNode != null)
                    {
                        // deactivate
                        currentNode.SignalHide();

                        // hide
                        if (hideOldNode)
                        {
                            currentNode.Visibility = Visibility.Collapsed;
                        }

                        // if needed - destroy
                        if (destroyOldNode)
                        {
                            Children.Remove(currentNode);

                            currentNode.SignalDestroy();
                            currentNode = null;
                        }
                    }

                    newNode.Visibility = Visibility.Visible;
                    newNode.SignalShow();
                });
            }
        }