更新:2007 年 11 月
命名空间:
System.Windows.Documents 程序集:
PresentationFramework(在 PresentationFramework.dll 中)
Dim instance As TextRange
public ref class TextRange
TextRange 类引入了以下术语。
所选内容 - TextRange 为由 TextPointers 指示的两个位置之间的所选内容。 这两个位置的其中一个根据所选内容放置一个固定的定位点,而另一个位置则是可移动的。 这与用户使用鼠标或键盘所进行的选择的行为类似。
当前所选内容 - 因为 TextRange 始终指示所选内容,所以可将由 TextRange 指示的所选内容称为当前所选内容。
文本容器 - 文本容器 是组成现有流内容的最终边框的元素;由 TextRange 指示的所选内容始终在文本容器内。 当前,文本容器必须是 FlowDocument 或 TextBlock。
文档 - 包含在文本容器中的全部内容称为文档。
有关其他相关术语(如位置)的更多信息,请参见 TextPointer。
下面的示例演示如何使用 TextRange 的 Text 属性来返回指定 FlowDocument 的纯文本表示形式。
// 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
参考