Xaml-textblock

提供:Dev Guides
移動先:案内検索

XAML-TextBlock

TextBlockは、少量の読み取り専用テキストを表示するための軽量なコントロールを提供します。 TextBlockクラスの階層的な継承は次のとおりです-

TextBlock Hierarchy

プロパティ

以下に、TextBlockクラスの一般的に使用されるプロパティを示します。

Sr.No. Property & Description
1

ContentEnd

TextBlockのテキストコンテンツの終わりのTextPointerオブジェクトを取得します。

2

ContentStart

TextBlockのテキストコンテンツの開始点のTextPointerオブジェクトを取得します。

3

IsTextSelectionEnabled

ユーザーアクションまたは選択関連APIの呼び出しによって、TextBlockでテキスト選択が有効になっているかどうかを示す値を取得または設定します。

4

IsTextSelectionEnabledProperty

IsTextSelectionEnabled依存プロパティを識別します。

5

LineHeight

コンテンツの各行の高さを取得または設定します。

6

MaxLines

TextBlockに表示されるテキストの最大行を取得または設定します。

7

SelectedText

選択したテキストのテキスト範囲を取得します。

8

SelectionEnd

TextBlockで選択されたテキストの終了位置を取得します。

9

SelectionHighlightColor

選択したテキストを強調表示するために使用されるブラシを取得または設定します。

10

SelectionStart

TextBlockで選択されたテキストの開始位置を取得します。

11

Text

TextBlockのテキストコンテンツを取得または設定します。

12

TextAlignment

テキストコンテンツの水平方向の配置を示す値を取得または設定します。

13

TextTrimming

コンテンツがコンテンツ領域をオーバーフローするときに使用するテキストのトリミング動作を取得または設定します。

14

TextWrapping

TextBlockによるテキストのラップ方法を取得または設定します。

イベント

以下に、TextBlockクラスの一般的に使用されるイベントを示します。

Sr.No. Event & Description
1

ContextMenuOpening

システムがコンテキストメニューを表示するインタラクションを処理するときに発生します。

2

SelectionChanged

テキストの選択が変更されたときに発生します。

方法

以下は、TextBlockクラスで一般的に使用されるメソッドです。

Sr.No. Method & Description
1

Focus

TextBlockを、従来のフォーカス可能なコントロールであるかのようにフォーカスします。

2

Select

TextBlock内のテキストの範囲を選択します。

3

SelectAll

TextBlockのコンテンツ全体を選択します。

次の例は、XAMLアプリケーションでのTextBlockの使用方法を示しています。 以下に、いくつかのプロパティを使用してTextBlockを作成および初期化するXAMLコードを示します。

<Window x:Class = "XAMLTextBlock.MainWindow"
   xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml"
   Title = "MainWindow" Height = "350" Width = "604">

   <Grid>
      <StackPanel>
         <TextBlock FontFamily = "Verdana"
            LineStackingStrategy = "MaxHeight"
            LineHeight = "10" Width = "500" TextWrapping = "Wrap">

            Use the <Run FontSize = "30"> LineStackingStrategy</Run>
            property to determine how a line box is created for each line.
            A value of <Run FontSize = "20">MaxHeight</Run>
            specifies that the stack height is the smallest value
            that contains all the inline elements on that line
            when those elements are properly aligned.
            A value of <Run FontSize = "20">BlockLineHeight</Run>
            specifies that the stack height is determined by
            the block element LineHeight property value.
         </TextBlock>
      </StackPanel>
   </Grid>

</Window>

上記のコードをコンパイルして実行すると、次の出力が生成されます-

TextBlock Output

上記のサンプルコードを実行し、他のいくつかのプロパティとイベントを試すことをお勧めします。