Ejemplo n.º 1
0
        /// <summary>
        /// Construct a TravelLog connected to a PivotViewer
        /// </summary>
        private TravelLog(PivotViewer pivotViewer, Uri initialCollectionUri)
        {
            m_pivotViewer = pivotViewer;
            m_travelLog = new Dictionary<string, TravelLogEntry>();
            m_currentTravelLogEntry = new TravelLogEntry(initialCollectionUri, string.Empty);

            // Hook the events that are needed to implement travel log
            m_pivotViewer.PropertyChanged += new PropertyChangedEventHandler(PivotViewer_PropertyChanged);
            App.Current.Host.NavigationStateChanged += OnHostNavigationStateChanged;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handle navigation by using an existing travel log mapping, or creating a new one
        /// </summary>
        private void TravelLogNavigation(string oldNavigationState, string newNavigationState)
        {
            if (newNavigationState.StartsWith("/viewerStateKey/") || string.IsNullOrEmpty(newNavigationState))
            {
                TravelLogEntry newTravelLogEntry = null;

                if (m_travelLog.TryGetValue(newNavigationState, out newTravelLogEntry)
                    && (m_pivotViewer.CollectionUri != newTravelLogEntry.CollectionUri
                        || m_pivotViewer.ViewerState != newTravelLogEntry.ViewerState))
                {
                    // There is a mapping from the navigation state to a travel log entry, and the state in the travel log entry
                    // is different from the current PivotViewer state, so apply the travel log entry state to get the appropriate
                    // forward/back effect

                    m_isNavigating = true;
                    m_hasItemIdBeenUpdatedFromCollectionLoad = false;

                    // Before updating the ViewerState, update the mapping from navigation state to refer to the current ViewerState
                    AddCurrentStateToTravelLog(oldNavigationState);

                    // Load the collection and ViewerState in the travel log entry, and set the targeted focus item which will be focused
                    // once the new ViewerState has settled
                    m_pivotViewer.LoadCollection(newTravelLogEntry.CollectionUri.ToString(), newTravelLogEntry.ViewerState);
                    m_pivotViewer.CurrentItemId = newTravelLogEntry.CurrentItem;

                    // Build up a new current entry for the state that will be loaded
                    m_currentTravelLogEntry = new TravelLogEntry(newTravelLogEntry.CollectionUri, newTravelLogEntry.ViewerState);
                }
                else
                {
                    // There is no mapping, or the state is the same as the existing state (for example, user moved from grid view
                    // to graph view, and back to grid view, then uses the travel log dropdown to back up two entries in one step,
                    // this should result in no state change to PivotViewer, except for possibly a current item change)
                    if (newTravelLogEntry != null)
                    {
                        AddCurrentStateToTravelLog(oldNavigationState, m_pivotViewer.CurrentItemId);
                        m_pivotViewer.CurrentItemId = newTravelLogEntry.CurrentItem;
                    }
                    else
                    {
                        AddCurrentStateToTravelLog(oldNavigationState);
                    }

                    // Build up a new current entry for the existing current state
                    m_currentTravelLogEntry = new TravelLogEntry(m_pivotViewer.CollectionUri, m_pivotViewer.ViewerState);
                }
            }
        }