少量のフロー コンテンツを表示する軽量コントロールを提供します。
名前空間: System.Windows.Controls
アセンブリ: PresentationFramework (presentationframework.dll 内)
XML 名前空間 : http://schemas.microsoft.com/winfx/2006/xaml/presentation
<ContentPropertyAttribute("Inlines")> _
<LocalizabilityAttribute(LocalizationCategory.Text)> _
Public Class TextBlock
Inherits FrameworkElement
Implements IContentHost, IAddChild, IServiceProvider
Dim instance As TextBlock
[ContentPropertyAttribute("Inlines")]
[LocalizabilityAttribute(LocalizationCategory.Text)]
public class TextBlock : FrameworkElement, IContentHost, IAddChild, IServiceProvider
[ContentPropertyAttribute(L"Inlines")]
[LocalizabilityAttribute(LocalizationCategory::Text)]
public ref class TextBlock : public FrameworkElement, IContentHost, IAddChild, IServiceProvider
/** @attribute ContentPropertyAttribute("Inlines") */
/** @attribute LocalizabilityAttribute(LocalizationCategory.Text) */
public class TextBlock extends FrameworkElement implements IContentHost, IAddChild,
IServiceProvider
ContentPropertyAttribute("Inlines")
LocalizabilityAttribute(LocalizationCategory.Text)
public class TextBlock extends FrameworkElement implements IContentHost, IAddChild,
IServiceProvider
<TextBlock>
Inlines
</TextBlock>
TextBlock は、Inline フロー コンテンツ要素のホストおよび表示をサポートします。サポートされている要素には、AnchoredBlock、Bold、Hyperlink、InlineUIContainer、Italic、LineBreak、Run、Span、Underline などがあります。
TextBlock は軽量になるように設計されており、特に少量のフロー コンテンツをユーザー インターフェイス (UI) に統合するために使用されます。TextBlock は 1 行を表示するために最適化されており、数行までのコンテンツを表示する場合には優れたパフォーマンスを提供します。
TextBlock は、数行以上のコンテンツを表示する必要があるシナリオには適していません。このようなシナリオでは、FlowDocument を適切な表示コントロールと組み合わせて使用すると、TextBlock より優れたパフォーマンスが得られます。FlowDocumentScrollViewer は TextBlock の次に軽量なフロー コンテンツ表示用コントロールであり、最小限の UI を含むスクロール コンテンツ エリアを提供します。FlowDocumentPageViewer は、フロー コンテンツの "1 ページずつ表示" の表示モードで最適化されています。FlowDocumentReader はフロー コンテンツを表示する機能を最も豊富にサポートしていますが、その分ヘビーウェイトになっています。
TextBlock 内でテキストを水平方向および垂直方向に配置するには、HorizontalContentAlignment プロパティおよび VerticalContentAlignment プロパティを使用します。ページのレイアウト内で TextBlock を配置するには、HorizontalAlignment プロパティおよび VerticalAlignment プロパティを使用します。
TextBlock 要素を使用する方法を次の例に示します。
<TextBlock Name="textBlock1" TextWrapping="Wrap">
<Bold>TextBlock</Bold> is designed to be <Italic>lightweight</Italic>,
and is geared specifically at integrating <Italic>small</Italic> portions
of flow content into a UI.
</TextBlock>
<Button Width="100" Margin="10">Click Me</Button>
<TextBlock Name="textBlock2"
TextWrapping="Wrap" Background="AntiqueWhite" TextAlignment="Center"
>
By default, a TextBlock provides no UI beyond simply displaying its contents.
</TextBlock>
<Button Width="100" Margin="10">Click Me</Button>
この例の表示結果を次の図に示します。
プログラムによって同様の結果を得る方法を次の例に示します。
TextBlock textBlock1 = new TextBlock();
TextBlock textBlock2 = new TextBlock();
textBlock1.TextWrapping = textBlock2.TextWrapping = TextWrapping.Wrap;
textBlock2.Background = Brushes.AntiqueWhite;
textBlock2.TextAlignment = TextAlignment.Center;
textBlock1.Inlines.Add(new Bold(new Run("TextBlock")));
textBlock1.Inlines.Add(new Run(" is designed to be "));
textBlock1.Inlines.Add(new Italic(new Run("lightweight")));
textBlock1.Inlines.Add(new Run(", and is geared specifically at integrating "));
textBlock1.Inlines.Add(new Italic(new Run("small")));
textBlock1.Inlines.Add(new Run(" portions of flow content into a UI."));
textBlock2.Text =
"By default, a TextBlock provides no UI beyond simply displaying its contents.";
System.Object
System.Windows.Threading.DispatcherObject
System.Windows.DependencyObject
System.Windows.Media.Visual
System.Windows.UIElement
System.Windows.FrameworkElement
System.Windows.Controls.TextBlock
この型の public static (Visual Basicでは共有) メンバはすべて,スレッド セーフです。インスタンス メンバの場合は,スレッド セーフであるとは限りません。
Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。
.NET Framework
サポート対象 : 3.0