TextRange.Text 属性

定义

获取或设置当前所选内容的纯文本内容。

public:
 property System::String ^ Text { System::String ^ get(); void set(System::String ^ value); };
public string Text { get; set; }
member this.Text : string with get, set
Public Property Text As String

属性值

String

一个字符串,其中包含当前所选内容的纯文本内容。

例外

当尝试将此属性设置为 null 时发生。

示例

以下示例演示了 Text 该属性的使用。

// 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

注解

使用此属性提取当前所选内容中的纯文本内容,而不考虑可能存在的任何格式。

对于此属性,新换行符和段落分隔符被视为等效项。 读取此属性时,当前所选内容中存在的任何类型的内容中断将转换为新行。

适用于