/// <summary> /// Removes the selected item from the selector's collection. /// </summary> public virtual void RemoveSelected() { if (SelectedIndex >= 0 && SelectedIndex < ItemsCore.Count) { ItemsCore.RemoveAt(SelectedIndex); } }
/// <summary> /// Replaces an item in the selector's collection. /// </summary> /// <param name="prevItem">The item to replace.</param> /// <param name="newItem">The item to replace <paramref name="prevItem" /> with.</param> /// <returns>true if the item could be replaced; otherwise, false.</returns> public virtual bool Replace(T prevItem, T newItem) { var index = ItemsCore.IndexOf(prevItem); if (index < 0) { return(false); } ItemsCore[index] = newItem; return(true); }
/// <summary> /// Removes the first occurrence of a specific object from the /// <see cref="T:System.Collections.Generic.ICollection`1" />. /// </summary> /// <param name="item">The object to remove from the <see cref="T:System.Collections.Generic.ICollection`1" />.</param> /// <returns> /// true if <paramref name="item" /> was successfully removed from the /// <see cref="T:System.Collections.Generic.ICollection`1" />; otherwise, false. This method also returns false if /// <paramref name="item" /> is not found in the original <see cref="T:System.Collections.Generic.ICollection`1" />. /// </returns> public virtual bool Remove(T item) { var index = ItemsCore.IndexOf(item); if (index < 0) { return(false); } ItemsCore.RemoveAt(index); return(true); }
protected virtual void OnTeardown() { foreach (var item in Items) { var disposable = item as IDisposable; if (disposable != null) { disposable.Dispose(); } } ItemsCore.Clear(); }
/// <summary> /// Replaces an item in the selector's collection and selects the new item. /// </summary> /// <param name="prevItem">The item to replace.</param> /// <param name="newItem">The item to replace <paramref name="prevItem" /> with.</param> /// <returns>true if the item could be replaced; otherwise, false.</returns> public virtual bool ReplaceAndSelect(T prevItem, T newItem) { var index = ItemsCore.IndexOf(prevItem); if (index < 0) { return(false); } if (index == SelectedIndex) { SelectedIndex = -1; } ItemsCore[index] = newItem; SelectedIndex = index; return(true); }
/// <summary> /// Inserts an item to the selector's collection at the specified index and selects it. /// </summary> /// <param name="index">The zero-based index at which <paramref name="item" /> should be inserted. index.</param> /// <param name="item">The object to insert.</param> public virtual void InsertAndSelect(int index, T item) { ItemsCore.Insert(index, item); SelectedIndex = index; }
/// <summary> /// Adds an item to the collection and selects it. /// </summary> /// <param name="item">The object to add.</param> public virtual void AddAndSelect(T item) { ItemsCore.Add(item); SelectedIndex = ItemsCore.Count - 1; }
/// <summary> /// Returns an enumerator that iterates through the collection. /// </summary> /// <returns> /// An enumerator that can be used to iterate through the collection. /// </returns> public IEnumerator <T> GetEnumerator() { return(ItemsCore.GetEnumerator()); }
/// <summary> /// Determines whether the <see cref="T:System.Collections.Generic.ICollection`1" /> contains a specific value. /// </summary> /// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.ICollection`1" />.</param> /// <returns> /// true if <paramref name="item" /> is found in the <see cref="T:System.Collections.Generic.ICollection`1" />; /// otherwise, false. /// </returns> public bool Contains(T item) { return(ItemsCore.Contains(item)); }
/// <summary> /// Removes all items from the <see cref="T:System.Collections.Generic.ICollection`1" />. /// </summary> public virtual void Clear() { ItemsCore.Clear(); }
/// <summary> /// Copies the elements of the <see cref="T:System.Collections.Generic.ICollection`1" /> to an /// <see cref="T:System.Array" />, starting at a particular <see cref="T:System.Array" /> index. /// </summary> /// <param name="array"> /// The one-dimensional <see cref="T:System.Array" /> that is the destination of the elements copied /// from <see cref="T:System.Collections.Generic.ICollection`1" />. The <see cref="T:System.Array" /> must have /// zero-based indexing. /// </param> /// <param name="arrayIndex">The zero-based index in <paramref name="array" /> at which copying begins.</param> public void CopyTo(T[] array, int arrayIndex) { ItemsCore.CopyTo(array, arrayIndex); }
/// <summary> /// Removes the <see cref="T:System.Collections.Generic.IList`1" /> item at the specified index. /// </summary> /// <param name="index">The zero-based index of the item to remove.</param> public virtual void RemoveAt(int index) { ItemsCore.RemoveAt(index); }
/// <summary> /// Inserts an item to the <see cref="T:System.Collections.Generic.IList`1" /> at the specified index. /// </summary> /// <param name="index">The zero-based index at which <paramref name="item" /> should be inserted.</param> /// <param name="item">The object to insert into the <see cref="T:System.Collections.Generic.IList`1" />.</param> public virtual void Insert(int index, T item) { ItemsCore.Insert(index, item); }
/// <summary> /// Determines the index of a specific item in the <see cref="T:System.Collections.Generic.IList`1" />. /// </summary> /// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.IList`1" />.</param> /// <returns> /// The index of <paramref name="item" /> if found in the list; otherwise, -1. /// </returns> public int IndexOf(T item) { return(ItemsCore.IndexOf(item)); }
/// <summary> /// Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1" />. /// </summary> /// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1" />.</param> public virtual void Add(T item) { ItemsCore.Add(item); }