示例#1
0
        /// <summary>
        /// Inserts the specified <see cref="ImageListBoxItem"/> into the <see
        /// cref="ItemsControl.Items"/> collection at an index position determined by its <see
        /// cref="ImageListBoxItem.SortKey"/>.</summary>
        /// <param name="item">
        /// The <see cref="ImageListBoxItem"/> to insert.</param>
        /// <returns>
        /// The index position within the <see cref="ItemsControl.Items"/> collection at which the
        /// specified <paramref name="item"/> was inserted.</returns>
        /// <remarks><para>
        /// <b>Insert</b> tests the specified <paramref name="item"/> against the existing <see
        /// cref="ItemsControl.Items"/> of type <see cref="ImageListBox"/> to determine its correct
        /// index position, according to their <see cref="ImageListBoxItem.SortKey"/> values.
        /// </para><para>
        /// The algorithm is a stable insertion sort, moving backward through the <see
        /// cref="ItemsControl.Items"/> collection for optimal performance when the added <paramref
        /// name="item"/> typically has the highest <see cref="ImageListBoxItem.SortKey"/>.
        /// </para></remarks>

        public int Insert(ImageListBoxItem item)
        {
            for (int i = Items.Count - 1; i >= 0; i--)
            {
                ImageListBoxItem cursor = Items[i] as ImageListBoxItem;
                if (cursor == null || item.SortKey.CompareOrdinal(cursor.SortKey) > 0)
                {
                    Items.Insert(i + 1, item);
                    return(i + 1);
                }
            }

            Items.Insert(0, item);
            return(0);
        }
示例#2
0
        /// <summary>
        /// Redraws all elements of the specified <see cref="IList"/> collection that are of type
        /// <see cref="ImageListBoxItem"/>.</summary>
        /// <param name="items">
        /// An <see cref="IList"/> containing the <see cref="ImageListBoxItem"/> items to redraw.
        /// This argument may be a null reference.</param>
        /// <remarks>
        /// <b>Redraw</b> invokes <see cref="UIElement.InvalidateVisual"/> on any specified
        /// <paramref name="items"/> that can be cast to <see cref="ImageListBoxItem"/>. Any other
        /// items are ignored.</remarks>

        public static void Redraw(IList items)
        {
            if (items == null)
            {
                return;
            }

            for (int i = 0; i < items.Count; i++)
            {
                ImageListBoxItem item = items[i] as ImageListBoxItem;
                if (item != null)
                {
                    item.InvalidateVisual();
                }
            }
        }