Class RunCollection
Represents a modifiable collection of Run objects used to create rich text with mixed formatting. When attached to a TextObject, changes to the collection automatically update the text display.
public class RunCollection : IList<Run>, ICollection<Run>, IEnumerable<Run>, IEnumerable
- Inheritance
-
RunCollection
- Implements
- Inherited Members
Constructors
RunCollection()
Initializes a new empty instance of the RunCollection class.
public RunCollection()
Examples
var runs = new RunCollection();
runs.Add(new Run("Hello") { Bold = true });
runs.Add(new Run("World") { Color = Color.red });
RunCollection(params Run[])
Initializes a new instance of the RunCollection class with the specified array of runs.
public RunCollection(params Run[] runs)
Parameters
Examples
var runs = new RunCollection(
new Run("Hello") { Bold = true },
new Run("World") { Color = Color.red }
);
Properties
Count
Gets the number of elements contained in the ICollection<T>.
public int Count { get; }
Property Value
- int
The number of elements contained in the ICollection<T>.
IsReadOnly
Gets a value indicating whether the ICollection<T> is read-only.
public bool IsReadOnly { get; }
Property Value
- bool
true if the ICollection<T> is read-only; otherwise, false.
this[int]
Gets or sets the element at the specified index.
public Run this[int index] { get; set; }
Parameters
index
intThe zero-based index of the element to get or set.
Property Value
- Run
The element at the specified index.
Exceptions
- ArgumentOutOfRangeException
index
is not a valid index in the IList<T>.- NotSupportedException
The property is set and the IList<T> is read-only.
Methods
Add(Run)
Adds an item to the ICollection<T>.
public void Add(Run item)
Parameters
item
RunThe object to add to the ICollection<T>.
Exceptions
- NotSupportedException
The ICollection<T> is read-only.
AddRange(IEnumerable<Run>)
Adds a collection of Run items to the current collection.
public void AddRange(IEnumerable<Run> items)
Parameters
items
IEnumerable<Run>The collection of Run items to add. Cannot be null.
Remarks
After adding the items, this method triggers a collection changed notification.
Clear()
Removes all items from the ICollection<T>.
public void Clear()
Exceptions
- NotSupportedException
The ICollection<T> is read-only.
Contains(Run)
Determines whether the ICollection<T> contains a specific value.
public bool Contains(Run item)
Parameters
item
RunThe object to locate in the ICollection<T>.
Returns
- bool
true if
item
is found in the ICollection<T>; otherwise, false.
CopyTo(Run[], int)
Copies the elements of the ICollection<T> to an Array, starting at a particular Array index.
public void CopyTo(Run[] array, int arrayIndex)
Parameters
array
Run[]The one-dimensional Array that is the destination of the elements copied from ICollection<T>. The Array must have zero-based indexing.
arrayIndex
intThe zero-based index in
array
at which copying begins.
Exceptions
- ArgumentNullException
array
is null.- ArgumentOutOfRangeException
arrayIndex
is less than 0.- ArgumentException
The number of elements in the source ICollection<T> is greater than the available space from
arrayIndex
to the end of the destinationarray
.
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<Run> GetEnumerator()
Returns
- IEnumerator<Run>
An enumerator that can be used to iterate through the collection.
IndexOf(Run)
Determines the index of a specific item in the IList<T>.
public int IndexOf(Run item)
Parameters
Returns
- int
The index of
item
if found in the list; otherwise, -1.
Insert(int, Run)
Inserts an item to the IList<T> at the specified index.
public void Insert(int index, Run item)
Parameters
index
intThe zero-based index at which
item
should be inserted.item
RunThe object to insert into the IList<T>.
Exceptions
- ArgumentOutOfRangeException
index
is not a valid index in the IList<T>.- NotSupportedException
The IList<T> is read-only.
Join(RunCollection, IEnumerable<RunCollection>)
Joins the given run collections together using the specified separator runs between each collection.
public static RunCollection Join(RunCollection separator, IEnumerable<RunCollection> runs)
Parameters
separator
RunCollectionA collection of runs to insert between each collection.
runs
IEnumerable<RunCollection>The sequence of run collections to join together.
Returns
- RunCollection
A new RunCollection containing all elements with the separator between them.
Join(RunCollection, IEnumerable<Run>)
Joins the given runs together using the specified separator runs between each element.
public static RunCollection Join(RunCollection separator, IEnumerable<Run> runs)
Parameters
separator
RunCollectionA collection of runs to insert between each element.
runs
IEnumerable<Run>The sequence of runs to join together.
Returns
- RunCollection
A new RunCollection containing all elements with the separator between them.
Join(string, IEnumerable<RunCollection>)
Joins the given run collections together using the specified string separator between each collection.
public static RunCollection Join(string separator, IEnumerable<RunCollection> runs)
Parameters
separator
stringThe string to insert between each collection.
runs
IEnumerable<RunCollection>The sequence of run collections to join together.
Returns
- RunCollection
A new RunCollection containing all elements with the separator between them.
Join(string, IEnumerable<Run>)
Joins the given runs together using the specified string separator between each element.
public static RunCollection Join(string separator, IEnumerable<Run> runs)
Parameters
separator
stringThe string to insert between each element.
runs
IEnumerable<Run>The sequence of runs to join together.
Returns
- RunCollection
A new RunCollection containing all elements with the separator between them.
Remove(Run)
Removes the first occurrence of a specific object from the ICollection<T>.
public bool Remove(Run item)
Parameters
item
RunThe object to remove from the ICollection<T>.
Returns
- bool
true if
item
was successfully removed from the ICollection<T>; otherwise, false. This method also returns false ifitem
is not found in the original ICollection<T>.
Exceptions
- NotSupportedException
The ICollection<T> is read-only.
RemoveAt(int)
Removes the IList<T> item at the specified index.
public void RemoveAt(int index)
Parameters
index
intThe zero-based index of the item to remove.
Exceptions
- ArgumentOutOfRangeException
index
is not a valid index in the IList<T>.- NotSupportedException
The IList<T> is read-only.
Events
CollectionChanged
Occurs when items in the collection are added, removed, or when the collection is cleared.
public event EventHandler? CollectionChanged