/// <summary> /// Standard ListBox method to return item containers (which are always LazyListBoxItems for us) /// </summary> /// <returns>Returns a new LazyListBoxItem</returns> protected override DependencyObject GetContainerForItemOverride() { LazyListBoxItem item = new LazyListBoxItem(); item.Owner = this; if (ItemContainerStyle != null) { item.Style = ItemContainerStyle; } return(item); }
/// <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); }
/// <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> /// Gets the index of the item housed by the given container /// </summary> /// <param name="container">The container to check</param> /// <returns>The index of the item that is housed in this container</returns> public int GetItemIndexFromContainer(LazyListBoxItem container) { return((stackPanel.ItemContainerGenerator as ItemContainerGenerator).IndexFromContainer(container)); }