TextRange クラス

定義

2 つの TextPointer 位置の間にあるコンテンツの選択範囲を表します。

public ref class TextRange
public class TextRange
type TextRange = class
Public Class TextRange
継承
TextRange
派生

次の例では、a TextRange のプロパティをText使用して、指定した文字列のプレーン テキスト表現を返します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 TextRange、TextPointers によって示される 2 つの位置の間のコンテンツの選択です。 これらのいずれかの位置は、選択に対して固定アンカーを配置し、もう一方の位置は移動可能です。 これは、マウスまたはキーボードを使用してユーザーが選択した動作に似ています。

  • 現在の選択範囲 - 常にコンテンツ内の選択範囲を示すのTextRangeで、単に現在の選択範囲 として示されるTextRange選択範囲を参照するのが理にかなっています。

  • テキスト コンテナー - テキスト コンテナー は、手元のフロー コンテンツの最終的な境界線を形成する要素です。によって示される選択範囲は、 TextRange 常にテキスト コンテナー内に含まれます。 現在、テキスト コンテナーは、次のいずれかFlowDocumentTextBlockである必要があります。

  • ドキュメント - テキスト コンテナー内にまとめて含まれるコンテンツは、 ドキュメント と呼ばれます。

ポジション などの他の関連用語の詳細については、以下を参照してくださいTextPointer

コンストラクター

TextRange(TextPointer, TextPointer)

新しい範囲の開始位置および終了位置として指定された 2 つの 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)

更新対象の選択範囲を示す 2 つの TextPointer 位置を取得して現在の選択範囲を更新します。

ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

events

Changed

コンテンツの新しいスパンをカバーするように範囲の位置が変更されたときに発生します。

適用対象

こちらもご覧ください