TextRange 類別

定義

表示兩個 TextPointer 位置之間的內容選取範圍。

public ref class TextRange
public class TextRange
type TextRange = class
Public Class TextRange
繼承
TextRange
衍生

範例

下列範例示範如何使用 TextTextRange 屬性傳回指定 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;
}
' 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

備註

類別 TextRange 介紹下列術語。

  • 選取 範圍 - A TextRangeTextPointers 所指出兩個位置之間的內容選取範圍。 其中一個位置是固定錨點相對於選取範圍,而另一個位置則是可移動的。 這與使用滑鼠或鍵盤的使用者所做的選取方式類似。

  • 目前的選取 範圍 - 因為 一 TextRange 律會指出內容中的選取範圍,所以只要將 所 TextRange 指示的選取範圍參照為 目前的選取範圍,就很合理。

  • 文字容器 - 文字容器 是構成手邊流程內容最終框線的專案;由 TextRange 指示的選取範圍一律落在文字容器內。 目前,文字容器必須是 FlowDocumentTextBlock

  • - 文字容器內統包含的內容稱為

如需其他相關詞彙的詳細資訊,例如 位置,請參閱 TextPointer

建構函式

TextRange(TextPointer, TextPointer)

取兩個指定的 TextRange 位置做為新範圍的開始和結束位置,初始化 TextPointer 類別的新執行個體。

屬性

End

取得標示選取範圍結尾的位置。

IsEmpty

取得值,這個值表示目前選取範圍是否是空的。

Start

取得標示選取範圍開頭的位置。

Text

取得或設定目前選取範圍的純文字內容。

方法

ApplyPropertyValue(DependencyProperty, Object)

將指定的格式化屬性和值套用至目前選取範圍。

CanLoad(String)

檢查是否可以用指定之資料格式的內容載入目前選取範圍。

CanSave(String)

檢查目前選取範圍是否可以另存為指定的資料格式。

ClearAllProperties()

從目前選取範圍移除所有格式化屬性 (由 Inline 項目表示)。

Contains(TextPointer)

檢查某個位置 (由 TextPointer 指定) 是否位於目前選取範圍內。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetPropertyValue(DependencyProperty)

傳回目前選取範圍上之指定格式化屬性的有效值。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
Load(Stream, String)

從指定的資料流載入指定之資料格式的目前選取範圍。

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
Save(Stream, String)

將目前選取範圍以指定的資料格式儲存至指定的資料流。

Save(Stream, String, Boolean)

使用保留自訂 TextElement 物件的選項,將目前選取範圍以指定的資料格式儲存至指定的資料流。

Select(TextPointer, TextPointer)

採用兩個 TextPointer 位置來表示更新過的選取範圍,以更新目前的選取範圍。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

事件

Changed

重新置放範圍以涵蓋新的內容範圍時發生。

適用於

另請參閱