System.Windows.Documents 命名 ...


.NET Framework 类库
TextRange 类

更新:2007 年 11 月

表示两个 TextPointer 位置之间的所选内容。

命名空间:  System.Windows.Documents
程序集:  PresentationFramework(在 PresentationFramework.dll 中)

语法

Visual Basic(声明)
Public Class TextRange
Visual Basic (用法)
Dim instance As TextRange
C#
public class TextRange
Visual C++
public ref class TextRange
J#
public class TextRange
JScript
public class TextRange
XAML
无法直接在 XAML 中创建此类的实例。
备注

TextRange 类引入了以下术语。

  • 所选内容 - TextRange 为由 TextPointers 指示的两个位置之间的所选内容。 这两个位置的其中一个根据所选内容放置一个固定的定位点,而另一个位置则是可移动的。 这与用户使用鼠标或键盘所进行的选择的行为类似。

  • 当前所选内容 - 因为 TextRange 始终指示所选内容,所以可将由 TextRange 指示的所选内容称为当前所选内容。

  • 文本容器 - 文本容器 是组成现有流内容的最终边框的元素;由 TextRange 指示的所选内容始终在文本容器内。 当前,文本容器必须是 FlowDocumentTextBlock

  • 文档 - 包含在文本容器中的全部内容称为文档。

有关其他相关术语(如位置)的更多信息,请参见 TextPointer

示例

下面的示例演示如何使用 TextRangeText 属性来返回指定 FlowDocument 的纯文本表示形式。

C#
// This method returns a plain text representation of a specified FlowDocument.
string GetTextFromFlowDocument(FlowDocument flowDoc)
{
     // Create a new TextRanage that takes the entire FlowDocument as the current selection.
     TextRange flowDocSelection = new TextRange(flowDoc.ContentStart, flowDoc.ContentEnd);

     // Use the Text property to extract a string that contains the unformatted text contents 
     // of the FlowDocument.
     return flowDocSelection.Text;
}
继承层次结构

System..::.Object
  System.Windows.Documents..::.TextRange
    System.Windows.Documents..::.TextSelection
线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。
平台

Windows Vista

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

版本信息

.NET Framework

受以下版本支持:3.5、3.0
另请参见

参考

标记 :


Page view tracker