TextRange(TextPointer, TextPointer) 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 TextRange 类的新实例,将两个指定的 TextPointer 位置作为新范围的开始和结束位置。
public:
TextRange(System::Windows::Documents::TextPointer ^ position1, System::Windows::Documents::TextPointer ^ position2);
public TextRange(System.Windows.Documents.TextPointer position1, System.Windows.Documents.TextPointer position2);
new System.Windows.Documents.TextRange : System.Windows.Documents.TextPointer * System.Windows.Documents.TextPointer -> System.Windows.Documents.TextRange
Public Sub New (position1 As TextPointer, position2 As TextPointer)
参数
- position1
- TextPointer
一个固定定位点位置,用于标记用于形成新 TextRange内容的选定内容的一端。
- position2
- TextPointer
一个可移动位置,用于标记用于形成新 TextRange内容的选定内容的另一端。
例外
在同一文档中未定位时position1发生。position2
在或为position1position2时null发生 。
示例
以下示例演示了 TextRange 构造函数的使用。
// 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;
}
' This method returns a plain text representation of a specified FlowDocument.
Private Function GetTextFromFlowDocument(ByVal flowDoc As FlowDocument) As String
' Create a new TextRanage that takes the entire FlowDocument as the current selection.
Dim flowDocSelection As 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
End Function
注解
A TextRange 由 TextPointers 指示的两个位置之间的选择构成。 其中一个位置(由 position1)相对于所选内容是固定的,而另一个位置(由 position2)是可移动的。 这类似于用户使用鼠标或键盘所做的选择的方式。
可以调整新 TextRange 内容的实际结尾,以匹配任何适用于包含新 TextRange文档的选择启发式。