Ejemplo n.º 1
0
        /// <summary>
        /// Synchronizes the shared source with the shared source provided.
        /// </summary>
        public void Sync(SharedSource <T> sharedSource)
        {
            var entries       = sharedSource.Entries;
            var items         = sharedSource.Items;
            var selectedIndex = sharedSource.SelectedIndex;

            this.handleSelectionChanged = false;
            this.ClearFast();
            int index = 0;

            foreach (var entry in entries)
            {
                var type = entry.SourceType;
                if (!typeof(T).IsAssignableFrom(type))
                {
                    throw new ArgumentException($"The type '{type.Name}' not inherits from '{typeof(T).Name}'");
                }

                var originalItem = items.ElementAt(index);
                var item         = NavigationHelper.EnsureNewView(originalItem);

                this.items.Insert(index, (T)item);
                this.entries.Insert(index, new NavigationEntry(type, entry.Parameter));
                index++;
            }
            this.handleSelectionChanged = true;
            if (selectedIndex >= 0 && this.items.Count > 0)
            {
                TrySelectItem(selectedIndex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the <see cref="SharedSource{T}"/>.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static SharedSource <T> CreateSharedSource <T>()
        {
            if (ContainsSharedSource <T>())
            {
                throw new InvalidOperationException($"A shared source source is already registered for '{typeof(T).Name}'");
            }

            var sharedSource = new SharedSource <T>();

            sharedSources[typeof(T)] = sharedSource;
            return(sharedSource);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a <see cref="SharedSource{T}"/> with a key.
        /// </summary>
        /// <typeparam name="T">The type</typeparam>
        /// <param name="key">The key</param>
        /// <returns></returns>
        public static SharedSource <T> CreateSharedSource <T>(string key)
        {
            var sharedSource = new SharedSource <T>();
            var type         = typeof(T);

            if (!keyedSharedSources.ContainsKey(type))
            {
                keyedSharedSources[type] = new Dictionary <string, ISharedSource>();
            }

            keyedSharedSources[type][key] = sharedSource;
            return(sharedSource);
        }