TextRange.Text 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定目前選擇的純文字內容。
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
屬性值
包含當前選擇的純文字內容的字串。
例外狀況
當嘗試將此屬性設為 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
備註
使用此特性擷取目前選取中的純文字內容,不論格式是否存在。
新行字元與段落分隔在此性質下視為等價。 當前選取中的任何類型的內容中斷,當讀取此屬性時,都會被轉換成新行。