Пример #1
0
        /// <summary>
        /// Standard listbox method to recycle items
        /// </summary>
        /// <param name="element">The LazyListBoxItem being recycled</param>
        /// <param name="item">The old item that's about to get thrown out</param>
        protected override void ClearContainerForItemOverride(DependencyObject element, object item)
        {
            LazyListBoxItem listBoxItem = (element as LazyListBoxItem);

#if false
            // Enable this if you are having issues with recycling
            Debug.WriteLine("Clearing container " + listBoxItem.Id + " for item " + item.ToString());
#endif

            // If it's a special ILazyDataItem, tell it to unload
            ILazyDataItem lazyItem = item as ILazyDataItem;
            if (lazyItem != null)
            {
                lazyItem.GoToState(LazyDataLoadState.Unloaded);
            }

            base.ClearContainerForItemOverride(element, item);
        }
Пример #2
0
        /// <summary>
        /// Standard method for recycling containers
        /// </summary>
        /// <param name="element">The LazyListBoxItem being prepared for a new object</param>
        /// <param name="item">The item that's about to be put into the container</param>
        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            LazyListBoxItem listBoxItem = (element as LazyListBoxItem);

#if false
            // Enable this if you are having issues with container recycling
            Debug.WriteLine("Preparing container " + listBoxItem.Id + " for item " + item.ToString());
#endif

            base.PrepareContainerForItemOverride(element, item);

            // If it's a special ILazyDataItem, tell it to go to the minimum loaded state
            ILazyDataItem lazyItem = item as ILazyDataItem;
            if (lazyItem != null && lazyItem.CurrentState == LazyDataLoadState.Unloaded)
            {
                lazyItem.GoToState(LazyDataLoadState.Minimum);
            }

            // Reset to the basic item template
            listBoxItem.ContentTemplate = ItemTemplate;
        }
        /// <summary>
        /// Forces the item to be visible or invisible
        /// </summary>
        /// <param name="isVisible">True if the item is visible, false otherwise</param>
        /// <param name="currentSnapshotVersion">Version information used for cache purposes</param>
        internal void SetIsVisible(bool isVisible, int currentSnapshotVersion)
        {
            // We have special behaviour if the item is an ILazyDataItem
            ILazyDataItem lazyItem = DataContext as ILazyDataItem;

            cachedIsVisible        = isVisible;
            visibleSnapshotVersion = currentSnapshotVersion;

            if (isVisible)
            {
                // If it's a special item, tell it to change states based on its current state
                if (lazyItem != null)
                {
                    LazyDataLoadState currentState = lazyItem.CurrentState;

                    // It was cached, so tell it to re-load
                    if (currentState == LazyDataLoadState.Cached)
                    {
                        lazyItem.GoToState(LazyDataLoadState.Reloading);
                    }

                    // It was loading and we asked it to pause; unpause it
                    else if (currentState == LazyDataLoadState.Loading || currentState == LazyDataLoadState.Reloading)
                    {
                        if (lazyItem.IsPaused)
                        {
                            lazyItem.Unpause();
                        }
                    }

                    // Otherwise, tell it to load unless it is already loading
                    else if (currentState != LazyDataLoadState.Loaded)
                    {
                        lazyItem.GoToState(LazyDataLoadState.Loading);
                    }
                }

                // Set the loaded item template, if it exists
                if (Owner.LoadedItemTemplate != null)
                {
                    ContentTemplate = Owner.LoadedItemTemplate;
                }
            }
            else
            {
                bool alreadyResetTemplate = false;

                // If it's a special item, tell it to change state
                if (lazyItem != null)
                {
                    // if the slow items are already loaded, switch to the cached template (vs the default template)
                    if (lazyItem.CurrentState == LazyDataLoadState.Loaded)
                    {
                        lazyItem.GoToState(LazyDataLoadState.Cached);
                        if (Owner.CachedItemTemplate != null)
                        {
                            ContentTemplate      = Owner.CachedItemTemplate;
                            alreadyResetTemplate = true;
                        }
                    }
                }

                // If we didn't set it to the CachedItemTemplate, then reset to the ItemTemplate
                if (alreadyResetTemplate != true && Owner.Template != null)
                {
                    ContentTemplate = Owner.ItemTemplate;
                }
            }
        }