Exemple #1
0
        /// <summary>
        /// Checks if the navigation source is registered.
        /// </summary>
        /// <param name="navigationSource">The navigation source</param>
        /// <returns>True if registered</returns>
        public bool IsRegistered(NavigationSource navigationSource)
        {
            if (navigationSource == null)
            {
                throw new ArgumentNullException(nameof(navigationSource));
            }

            return(this.navigationSources.Contains(navigationSource));
        }
        /// <summary>
        /// Creates the <see cref="NavigationSourceCommands"/>.
        /// </summary>
        /// <param name="navigationSource">The navigation source</param>
        public NavigationSourceCommands(NavigationSource navigationSource)
        {
            if (navigationSource == null)
            {
                throw new ArgumentNullException(nameof(navigationSource));
            }

            this.navigationSource = navigationSource;
            this.navigationSource.CanMoveToPreviousChanged += OnCanMoveToPreviousChanged;
            this.navigationSource.CanMoveToNextChanged     += OnCanMoveToNextChanged;
        }
Exemple #3
0
        /// <summary>
        /// Removes the <see cref="NavigationSource"/>.
        /// </summary>
        /// <param name="navigationSource">The navigation source</param>
        public bool Unregister(NavigationSource navigationSource)
        {
            if (navigationSource == null)
            {
                throw new ArgumentNullException(nameof(navigationSource));
            }

            if (this.navigationSources.Contains(navigationSource))
            {
                return(this.navigationSources.Remove(navigationSource));
            }
            return(false);
        }
Exemple #4
0
        /// <summary>
        /// Adds the <see cref="NavigationSource"/>.
        /// </summary>
        /// <param name="navigationSource">The navigation source</param>
        public void Register(NavigationSource navigationSource)
        {
            if (navigationSource == null)
            {
                throw new ArgumentNullException(nameof(navigationSource));
            }

            if (navigationSources.Count > 0)
            {
                navigationSource.Sync(navigationSources[0]);
            }

            this.navigationSources.Add(navigationSource);
        }
        /// <summary>
        /// Removes the <see cref="NavigationSource"/> from the <see cref="NavigationSourceContainer"/>.
        /// </summary>
        /// <param name="sourceName">The source name</param>
        /// <param name="navigationSource">The navigation source</param>
        /// <returns>True if removed</returns>
        public static bool RemoveNavigationSource(string sourceName, NavigationSource navigationSource)
        {
            if (sourceName == null)
            {
                throw new ArgumentNullException(nameof(sourceName));
            }
            if (navigationSource == null)
            {
                throw new ArgumentNullException(nameof(navigationSource));
            }

            if (allNavigationSources.TryGetValue(sourceName, out NavigationSourceContainer navigationSourceContainer))
            {
                if (navigationSourceContainer.IsRegistered(navigationSource))
                {
                    return(navigationSourceContainer.Unregister(navigationSource));
                }
            }
            return(false);
        }
        /// <summary>
        /// Adds the <see cref="NavigationSource"/>. The <see cref="NavigationSourceContainer"/> is created if the <see cref="AllNavigationSources"/> does not contain the source name.
        /// </summary>
        /// <param name="sourceName">The source name</param>
        /// <param name="navigationSource">The navigation source</param>
        public static void AddNavigationSource(string sourceName, NavigationSource navigationSource)
        {
            if (sourceName == null)
            {
                throw new ArgumentNullException(nameof(sourceName));
            }
            if (navigationSource == null)
            {
                throw new ArgumentNullException(nameof(navigationSource));
            }

            if (allNavigationSources.TryGetValue(sourceName, out NavigationSourceContainer navigationSourceContainer))
            {
                navigationSourceContainer.Register(navigationSource);
            }
            else
            {
                navigationSourceContainer = new NavigationSourceContainer();
                navigationSourceContainer.Register(navigationSource);
                allNavigationSources[sourceName] = navigationSourceContainer;
            }
        }
Exemple #7
0
        /// <summary>
        /// Synchronizes the navigation source with the navigation source provided.
        /// </summary>
        public void Sync(NavigationSource navigationSource)
        {
            this.ClearSources();

            var entries      = navigationSource.Entries;
            var sources      = navigationSource.Sources;
            var currentIndex = navigationSource.CurrentIndex;

            object currentSource    = null;
            object currentParameter = null;
            int    index            = 0;

            foreach (var entry in entries)
            {
                var originalSource = sources.ElementAt(index);
                var source         = NavigationHelper.EnsureNewView(originalSource);

                this.InsertSourceInternal(index, entry.SourceType, source, entry.Parameter);

                if (index == currentIndex)
                {
                    currentSource    = source;
                    currentParameter = entry.Parameter;
                }
                index++;
            }

            if (currentIndex != -1)
            {
                this.UpdateEntryParameter(currentIndex, currentParameter);
                this.SetCurrentIndex(currentIndex);
                this.SetCurrent(currentSource);

                CheckCanMoveTo(false, false);
            }
        }