Export (0) Print
Expand All

TextChangedEventArgs.Changes Property

Gets a collection of objects that contains information about the changes that occurred.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

public ICollection<TextChange> Changes { get; }

Property Value

Type: System.Collections.Generic.ICollection<TextChange>
A collection of objects that contains information about the changes that occurred.

There is one TextChange object for each consecutive change to the control. More than one consecutive change can occur during one occurrence of the TextChanged event when the change entails changing the structure of the underlying document.

For example, suppose that a RichTextBox contains the string "This is some text." The structure of the RichTextBox.Document is <Paragraph><Run>This is some text.</Run></Paragraph>. If the user bolds the words "is some", the structure of the underlying FlowDocument changes to <Paragraph><Run>This </Run><Run FontWeight="Bold">is some</Run><Run> text.</Run></Paragraph>. There are actually four changes that took place as a result of the user's action:

  1. The <Run> symbol is removed and re-added before the word This.

  2. The symbols </Run><Run> are added after the word This.

  3. The symbols </Run><Run> are added after the word some.

  4. The </Run> symbol is removed and re-added after the word Text.

In general, the following will always be true:

  • The changes that occur result in the document being in a valid state.

  • The collection is ordered consecutively, related to where the change occurred in the control. For example, a TextChange object that represents a change at position 2 is before a TextChange object that represents a change at position 10.

  • Two TextChange objects do not represent an overlapping area. The value of Offset plus the value of AddedLength of one TextChange object is always less than or equal to the value of Offset of the next TextChange object in the collection. Likewise, the value of Offset plus the value of RemovedLength of one TextChange object is always less than or equal to the value of Offset of the next TextChange object in the collection.

  • The collection reflects whatever changes occurred, even if there seems to be no net change. In the preceding example, neither the first or fourth change results in a net change, because each simply removed and re-added the <Run> and </Run> symbols, respectively. But the symbols were actually removed and added, so they are included in the collection.

If the TextChanged event occurs as a result of a property change, Changes is an empty collection. In the preceding example, if the user bolds the entire string, the FontWeight property of the Run is set to Bold, but nothing is added or removed from the document, so Changes is empty.

Changes is introduced in the .NET Framework version 3.5. For more information, see .NET Framework Versions and Dependencies.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5 SP1, 3.0 SP1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft