Udostępnij przez


TextRange.Text Właściwość

Definicja

Pobiera lub ustawia zawartość zwykłego tekstu bieżącego zaznaczenia.

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

Wartość właściwości

Ciąg zawierający zawartość zwykłego tekstu bieżącego zaznaczenia.

Wyjątki

Występuje, gdy podjęto próbę ustawienia tej właściwości na null.

Przykłady

W poniższym przykładzie pokazano użycie Text właściwości.

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

Uwagi

Użyj tej właściwości, aby wyodrębnić zawartość zwykłego tekstu w bieżącym zaznaczeniu, niezależnie od dowolnego formatowania, które może być obecne.

Nowe znaki wiersza i podziały akapitów są traktowane jako równoważne w odniesieniu do tej właściwości. Wszelkie typy podziałów zawartości obecnych w bieżącym zaznaczeniu są konwertowane na nowe wiersze po odczytaniu tej właściwości.

Dotyczy