TextBlock 类

定义

提供用于显示少量文本的轻型控件。

public ref class TextBlock sealed : FrameworkElement
/// [Windows.Foundation.Metadata.Activatable(65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.UI.Xaml.Markup.ContentProperty(Name="Inlines")]
class TextBlock final : FrameworkElement
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.UI.Xaml.Markup.ContentProperty(Name="Inlines")]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
class TextBlock final : FrameworkElement
[Windows.Foundation.Metadata.Activatable(65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.UI.Xaml.Markup.ContentProperty(Name="Inlines")]
public sealed class TextBlock : FrameworkElement
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.UI.Xaml.Markup.ContentProperty(Name="Inlines")]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
public sealed class TextBlock : FrameworkElement
Public NotInheritable Class TextBlock
Inherits FrameworkElement
<TextBlock ...>text</TextBlock>
-or-
<TextBlock>
  oneOrMoreInlineElements
</TextBlock>
-or-
<TextBlock .../>
继承
Object Platform::Object IInspectable DependencyObject UIElement FrameworkElement TextBlock
属性

Windows 要求

设备系列
Windows 10 (在 10.0.10240.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)

示例

提示

有关详细信息、设计指南和代码示例,请参阅 文本块

WinUI 2 库应用包括大多数 WinUI 2 控件、特性和功能的交互式示例。 通过 Microsoft Store 获取应用,或在 GitHub 上获取源代码。

此示例演示启用了文本选择和文本环绕的 TextBlock。

重要

如果在 TextBlock 中使用键盘进行文本选择,则用户必须先在前台使用应用激活 插入点浏览 (,然后按 F7) 。

呈现的文本如下所示:

包含换行文本的文本块
<TextBlock Text="This text demonstrates the wrapping behavior of a TextBlock." Width="240"
           IsTextSelectionEnabled="True" TextWrapping="Wrap"/>
TextBlock textBlock = new TextBlock();
textBlock.Text = "This text demonstrates the wrapping behavior of a TextBlock.";
textBlock.Width = 240;
textBlock.IsTextSelectionEnabled = true;
textBlock.TextWrapping = TextWrapping.Wrap;

// Add TextBlock to the visual tree.
rootPanel.Children.Add(textBlock);

此示例演示如何使用单个 文本运行 自定义 TextBlock 的外观。 FontWeightFontFamilyFontStyleForeground color 和 SelectionHighlightColor 属性是自定义的。

呈现的文本如下所示:

带格式文本的文本块
<TextBlock Text="This text demonstrates some TextBlock properties." 
           IsTextSelectionEnabled="True" 
           SelectionHighlightColor="Green" 
           Foreground="Blue" 
           FontWeight="Light" 
           FontFamily="Arial" 
           FontStyle="Italic"/>
TextBlock textBlock = new TextBlock();
textBlock.Text = "This text demonstrates some TextBlock properties.";
textBlock.IsTextSelectionEnabled = true;
textBlock.SelectionHighlightColor = new SolidColorBrush(Windows.UI.Colors.Green);
textBlock.Foreground = new SolidColorBrush(Windows.UI.Colors.Blue);
textBlock.FontWeight = Windows.UI.Text.FontWeights.Light;
textBlock.FontFamily = new FontFamily("Arial");
textBlock.FontStyle = Windows.UI.Text.FontStyle.Italic;

// Add TextBlock to the visual tree.
rootPanel.Children.Add(textBlock);

此示例演示如何在 TextBlock 中自定义不同的内联元素。

呈现的文本如下所示:

带有带格式的内联元素的文本块
<TextBlock IsTextSelectionEnabled="True" SelectionHighlightColor="Green" FontFamily="Arial">
    <Run Foreground="Blue" FontWeight="Light" Text="This text demonstrates "></Run>
    <Span FontWeight="SemiBold">
        <Run FontStyle="Italic">the use of inlines </Run>
        <Run Foreground="Red">with formatting.</Run>
    </Span>
</TextBlock>
TextBlock textBlock = new TextBlock();
textBlock.IsTextSelectionEnabled = true;
textBlock.SelectionHighlightColor = new SolidColorBrush(Windows.UI.Colors.Green);
textBlock.FontFamily = new FontFamily("Arial");

// For Run and Span, add 'using Windows.UI.Xaml.Documents;'
Windows.UI.Xaml.Documents.Run run = new Run();
run.Foreground = new SolidColorBrush(Windows.UI.Colors.Blue);
run.FontWeight = Windows.UI.Text.FontWeights.Light;
run.Text = "This text demonstrates ";

Windows.UI.Xaml.Documents.Span span = new Span();
span.FontWeight = Windows.UI.Text.FontWeights.SemiBold;

Run run1 = new Run();
run1.FontStyle = Windows.UI.Text.FontStyle.Italic;
run1.Text = "the use of inlines ";

Run run2 = new Run();
run2.Foreground = new SolidColorBrush(Windows.UI.Colors.Red);
run2.Text = "with formatting.";

span.Inlines.Add(run1);
span.Inlines.Add(run2);
textBlock.Inlines.Add(run);
textBlock.Inlines.Add(span);

// Add TextBlock to the visual tree.
rootPanel.Children.Add(textBlock);

此示例演示如何使用内联超链接。 有关详细信息,请参阅 超链接

<TextBlock><Hyperlink xml:space="preserve" NavigateUri="http://www.bing.com"> Hyperlink to Bing </Hyperlink></TextBlock>
// Create a TextBlock this is needed to put the hyperlink inside
TextBlock textBlock = new TextBlock();

// Create a Hyperlink and a Run. 
// The Run is used as the visible content of the hyperlink.
Hyperlink hyperlink = new Hyperlink();
Run run = new Run();

// Set the Text property on the run. 
// This is the visible text of the hyperlink.
run.Text = " Hyperlink to Bing ";

// Add the Run to the Hyperlink. 
hyperlink.Inlines.Add(run);

// Set the URI for the Hyperlink. 
hyperlink.NavigateUri = new Uri("http://www.bing.com");

// Add the Hyperlink to the TextBlock.
textBlock.Inlines.Add(hyperlink);

// Add TextBlock to the visual tree.        
rootPanel.Children.Add(textBlock);

下面的示例演示如何使用 LineStackingStrategy 属性来确定如何为 TextBlock 的文本行创建行框。 第一个 TextBlock 的 LineStackingStrategy 值为 MaxHeight,第二个 TextBlock 的值为 BlockLineHeight,第三个 TextBlock 的值为 BaselineToBaseline

呈现的文本如下所示:

文本块行堆叠策略
<StackPanel>

<!-- This TextBlock has a LineStackingStrategy set to "MaxHeight". -->
<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. A value of 
    <Run FontSize="20">BaselineToBaseline</Run> specifies that the stack height is determined by adding 
    LineHeight to the baseline of the previous line.
</TextBlock>

<!-- With a margin pushing down 20 pixels, draw a line just above the second textblock. -->
<!-- The fonts will reach above the LineHeight size and over the line. -->
<StackPanel Margin="0,20,0,0" HorizontalAlignment="Center">
    <Line Stroke="Green"  X2="500" />
</StackPanel>

<!-- Here is the same TextBlock but the LineStackingStrategy is set to "BlockLineHeight". -->
<TextBlock FontFamily="Verdana"
           LineStackingStrategy="BlockLineHeight" 
           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. A value of 
    <Run FontSize="20">BaselineToBaseline</Run> specifies that the stack height is determined by adding 
    LineHeight to the baseline of the previous line.
</TextBlock>

<!-- With a margin pushing down 20 pixels, draw a line just above the third textblock. -->
<StackPanel Margin="0,20,0,0" HorizontalAlignment="Center">
    <Line Stroke="Green"  X2="500" />
</StackPanel>

<!-- Here is the same TextBlock but the LineStackingStrategy is set to "BaselineToBaseline". -->
<TextBlock FontFamily="Verdana"
           LineStackingStrategy="BaselineToBaseline" 
           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. A value of 
    <Run FontSize="20">BaselineToBaseline</Run> specifies that the stack height is determined by adding 
    LineHeight to the baseline of the previous line.
</TextBlock>

</StackPanel>

注解

提示

有关详细信息、设计指南和代码示例,请参阅 文本块

TextBlock 是用于在应用中显示只读文本的主要控件。 你可以使用它来显示单行或多行文本、内联超链接以及粗体、斜体或带下划线格式的文本。

文本块控件

RichTextBlock 相比,TextBlock 通常更易于使用,并提供更好的文本呈现性能,因此它是大多数应用 UI 文本的首选。 它还提供许多用于自定义文本呈现方式的相同格式设置选项。 虽然你可以在文本中放入换行符,但 TextBlock 旨在显示一个段落且不支持文本缩进。 如果需要支持多个段落、多列文本或内联 UI 元素(如图像),请考虑 使用 RichTextBlock

文本性能

从 Windows 10 开始,对 TextBlock 进行了性能改进,减少了总体内存使用量,并大大减少了执行文本测量和排列的 CPU 时间。 若要详细了解这些性能改进以及如何确保使用它们,请参阅 TextBlock 控件指南的性能注意事项部分。

内置文本样式

可以使用平台随附Windows 10文本样式,使文本样式与系统中使用的文本对齐。 下面介绍如何使用内置样式与Windows 10类型渐变对齐。 有关详细信息,请参阅 XAML 主题资源

<TextBlock Text="Header" Style="{StaticResource HeaderTextBlockStyle}"/>
<TextBlock Text="SubHeader" Style="{StaticResource SubheaderTextBlockStyle}"/>
<TextBlock Text="Title" Style="{StaticResource TitleTextBlockStyle}"/>
<TextBlock Text="SubTitle" Style="{StaticResource SubtitleTextBlockStyle}"/>
<TextBlock Text="Base" Style="{StaticResource BaseTextBlockStyle}"/>
<TextBlock Text="Body" Style="{StaticResource BodyTextBlockStyle}"/>
<TextBlock Text="Caption" Style="{StaticResource CaptionTextBlockStyle}"/>

呈现的文本如下所示:

文本块样式

颜色字体

默认情况下,TextBlock 支持显示颜色字体。 系统上的默认颜色字体为 Segoe UI 表情符号,TextBlock 将回退到此字体以彩色显示字形。 有关详细信息,请参阅 IsColorFontEnabled 属性。

<TextBlock FontSize="30">Hello ☺⛄☂♨⛅</TextBlock>

呈现的文本如下所示:

带有颜色字体的文本块

版本历史记录

Windows 版本 SDK 版本 增值
1607 14393 GetAlphaMask
1703 15063 TextDecorations
1709 16299 HorizontalTextAlignment
1709 16299 IsTextTrimmed
1709 16299 IsTextTrimmedChanged
1709 16299 TextHighlighters
1809 17763 CopySelectionToClipboard
1809 17763 SelectionFlyout

构造函数

TextBlock()

初始化 TextBlock 类的新实例。

属性

AccessKey

获取或设置此元素的访问键 (助记) 。

(继承自 UIElement)
AccessKeyScopeOwner

获取或设置一个源元素,该元素提供此元素的访问键范围,即使它不在源元素的可视化树中也是如此。

(继承自 UIElement)
ActualHeight

获取 FrameworkElement 的呈现高度。 请参阅“备注”。

(继承自 FrameworkElement)
ActualOffset

获取此 UIElement 相对于其父级的位置,该位置在布局过程的排列过程期间计算。

(继承自 UIElement)
ActualSize

获取此 UIElement 在布局过程的排列过程中计算的大小。

(继承自 UIElement)
ActualTheme

获取元素当前使用的 UI 主题,该主题可能与 RequestedTheme 不同。

(继承自 FrameworkElement)
ActualWidth

获取 FrameworkElement 的呈现宽度。 请参阅“备注”。

(继承自 FrameworkElement)
AllowDrop

获取或设置一个值,该值确定此 UIElement 是否可以作为拖放操作的放置目标。

(继承自 UIElement)
AllowFocusOnInteraction

获取或设置一个值,该值指示当用户与元素交互时是否自动获取焦点。

(继承自 FrameworkElement)
AllowFocusWhenDisabled

获取或设置禁用的控件是否可以接收焦点。

(继承自 FrameworkElement)
BaselineOffset

返回一个值,每行文本都与基线相差。

BaseUri

获取统一资源标识符 (URI) ,表示 XAML 加载时 XAML 构造对象的基本统一资源标识符 (URI) 。 此属性在运行时用于统一资源标识符 (URI) 解析。

(继承自 FrameworkElement)
CacheMode

获取或设置一个值,该值指示应尽可能将呈现的内容缓存为复合位图。

(继承自 UIElement)
CanBeScrollAnchor

获取或设置一个值,该值指示 UIElement 是否可以成为滚动定位的候选项。

(继承自 UIElement)
CanDrag

获取或设置一个值,该值指示是否可以在拖放操作中将元素作为数据拖动。

(继承自 UIElement)
CenterPoint

获取或设置 元素的中心点,该中心点是关于发生旋转或缩放的点。 影响元素的呈现位置。

(继承自 UIElement)
CharacterSpacing

获取或设置字符之间的统一间距,单位为 1/1000 em。

CharacterSpacingProperty

标识 CharacterSpacing 依赖属性。

Clip

获取或设置用于定义 UIElement 内容的大纲的 RectangleGeometry

(继承自 UIElement)
CompositeMode

获取或设置一个属性,该属性声明元素在其父布局和窗口中的替代组合和混合模式。 这与混合 XAML/Microsoft DirectX UI 中涉及的元素相关。

(继承自 UIElement)
ContentEnd

获取 TextBlock 中文本内容的末尾的 TextPointer 对象。

ContentStart

获取 TextBlock 中文本内容的开头的 TextPointer 对象。

ContextFlyout

获取或设置与此元素关联的浮出控件。

(继承自 UIElement)
DataContext

获取或设置 FrameworkElement 的数据上下文。 数据上下文的常见用途是 当 FrameworkElement 使用 {Binding} 标记扩展并参与数据绑定时。

(继承自 FrameworkElement)
DesiredSize

获取此 UIElement 在布局过程的度量传递期间计算的大小。

(继承自 UIElement)
Dispatcher

获取与此对象关联的 CoreDispatcherCoreDispatcher 表示可以访问 UI 线程上的 DependencyObject 的工具,即使代码是由非 UI 线程启动的。

(继承自 DependencyObject)
ExitDisplayModeOnAccessKeyInvoked

获取或设置一个值,该值指定在调用访问密钥时是否消除访问密钥显示。

(继承自 UIElement)
FlowDirection

获取或设置文本和其他 UI 元素在控制其布局的任何父元素中的流动方向。 此属性可以设置为 LeftToRightRightToLeft。 在任何元素上将 FlowDirection 设置为 RightToLeft 会将对齐方式设置为右对齐,将阅读顺序设置为从右到左,并将控件的布局设置为从右到左流动。

(继承自 FrameworkElement)
FocusVisualMargin

获取或设置 FrameworkElement 的焦点视觉对象的外部边距。

(继承自 FrameworkElement)
FocusVisualPrimaryBrush

获取或设置用于为 FrameworkElement 绘制或Reveal焦点视觉对象的外边框HighVisibility的画笔。

(继承自 FrameworkElement)
FocusVisualPrimaryThickness

获取或设置 FrameworkElementHighVisibilityReveal焦点视觉对象的外边框的粗细。

(继承自 FrameworkElement)
FocusVisualSecondaryBrush

获取或设置用于为 FrameworkElement 绘制或Reveal焦点视觉对象的内边框HighVisibility的画笔。

(继承自 FrameworkElement)
FocusVisualSecondaryThickness

获取或设置 FrameworkElementHighVisibilityReveal焦点视觉对象的内边框的粗细。

(继承自 FrameworkElement)
FontFamily

获取或设置此元素中文本内容的首选顶级字体系列。

FontFamilyProperty

标识 FontFamily 依赖属性。

FontSize

获取或设置此元素中文本内容的字号。

FontSizeProperty

标识 FontSize 依赖属性。

FontStretch

获取或设置此元素中文本内容的字体拉伸。

FontStretchProperty

标识 FontStretch 依赖属性。

FontStyle

获取或设置此元素中内容的字体样式。

FontStyleProperty

标识 FontStyle 依赖属性。

FontWeight

获取或设置 TextBlock 的顶级字体粗细。

FontWeightProperty

标识 FontWeight 依赖属性。

Foreground

获取或设置要应用于 TextBlock 的文本内容的 Brush

ForegroundProperty

标识 前台 依赖属性。

Height

获取或设置 FrameworkElement 的建议高度。

(继承自 FrameworkElement)
HighContrastAdjustment

获取或设置一个值,该值指示在启用高对比度主题时框架是否自动调整元素的视觉属性。

(继承自 UIElement)
HorizontalAlignment

获取或设置在布局父级(如面板或项控件)中组合时应用于 FrameworkElement 的水平对齐特征。

(继承自 FrameworkElement)
HorizontalTextAlignment

获取或设置一个值,该值指示文本在 TextBlock 中的对齐方式。

HorizontalTextAlignmentProperty

标识 HorizontalTextAlignment 依赖属性。

Inlines

获取 TextBlock 中内联文本元素的集合。

IsAccessKeyScope

获取或设置一个值,该值指示元素是否定义其自己的访问键范围。

(继承自 UIElement)
IsColorFontEnabled

获取或设置一个值,该值确定是否以颜色呈现包含颜色层(如 Segoe UI 表情符号)的字体字形。

IsColorFontEnabledProperty

标识 IsColorFontEnabled 依赖属性。

IsDoubleTapEnabled

获取或设置一个值,该值确定 DoubleTapped 事件是否可以源自该元素。

(继承自 UIElement)
IsHitTestVisible

获取或设置此 UIElement 的包含区域是否可以为命中测试返回 true 值。

(继承自 UIElement)
IsHoldingEnabled

获取或设置一个值,该值确定 Holding 事件是否可以源自该元素。

(继承自 UIElement)
IsLoaded

获取一个值,该值指示元素是否已添加到元素树中并已准备好进行交互。

(继承自 FrameworkElement)
IsRightTapEnabled

获取或设置一个值,该值确定 RightTapped 事件是否可以源自该元素。

(继承自 UIElement)
IsTapEnabled

获取或设置一个值,该值确定 Tapped 事件是否可以源自该元素。

(继承自 UIElement)
IsTextScaleFactorEnabled

获取或设置是否启用自动文本放大,以反映系统文本大小设置。

IsTextScaleFactorEnabledProperty

标识 IsTextScaleFactorEnabled 依赖属性。

IsTextSelectionEnabled

获取或设置一个值,该值指示是否通过用户操作或调用与选择相关的 API 在 TextBlock 中启用文本选择。

IsTextSelectionEnabledProperty

标识 IsTextSelectionEnabled 依赖属性。

IsTextTrimmed

获取一个值,该值指示控件是否具有溢出内容区域的剪裁文本。

IsTextTrimmedProperty

标识 IsTextTrimmed 依赖属性。

KeyboardAcceleratorPlacementMode

获取或设置一个值,该值指示控件 工具提示 是否显示其关联的键盘快捷键的组合键。

(继承自 UIElement)
KeyboardAcceleratorPlacementTarget

获取或设置一个值,该值指示显示快捷键组合的控件 工具提示

(继承自 UIElement)
KeyboardAccelerators

获取使用键盘调用操作的组合键的集合。

加速器通常分配给按钮或菜单项。

显示各种菜单项的键盘快捷键的菜单示例
显示各种菜单项的键盘快捷键的菜单示例

(继承自 UIElement)
KeyTipHorizontalOffset

获取或设置一个值,该值指示键提示相对于 UIElement 的左或右放置距离。

(继承自 UIElement)
KeyTipPlacementMode

获取或设置一个值,该值指示相对于 UIElement 边界放置访问键提示的位置。

(继承自 UIElement)
KeyTipTarget

获取或设置一个值,该值指示访问键提示所针对的元素。

(继承自 UIElement)
KeyTipVerticalOffset

获取或设置一个值,该值指示键提示相对于 UI 元素的放置距离。

(继承自 UIElement)
Language

获取或设置适用于 FrameworkElement 以及对象表示形式和 UI 中当前 FrameworkElement 的所有子元素的本地化/全球化语言信息。

(继承自 FrameworkElement)
Lights

获取附加到此元素的 XamlLight 对象的集合。

(继承自 UIElement)
LineHeight

获取或设置各行内容的高度。

LineHeightProperty

标识 LineHeight 依赖属性。

LineStackingStrategy

获取或设置一个值,该值指示如何为 TextBlock 中的每一行文本确定行框。

LineStackingStrategyProperty

标识 LineStackingStrategy 依赖属性。

ManipulationMode

获取或设置用于 UIElement 行为和手势交互的 ManipulationModes 值。 设置此值可处理应用代码中此元素的操作事件。

(继承自 UIElement)
Margin

获取或设置 FrameworkElement 的外部边距。

(继承自 FrameworkElement)
MaxHeight

获取或设置 FrameworkElement 的最大高度约束。

(继承自 FrameworkElement)
MaxLines

获取或设置 TextBlock 中显示的文本的最大行数。

MaxLinesProperty

标识 MaxLines 依赖属性。

MaxWidth

获取或设置 FrameworkElement 的最大宽度约束。

(继承自 FrameworkElement)
MinHeight

获取或设置 FrameworkElement 的最小高度约束。

(继承自 FrameworkElement)
MinWidth

获取或设置 FrameworkElement 的最小宽度约束。

(继承自 FrameworkElement)
Name

获取或设置对象的标识名称。 当 XAML 处理器从 XAML 标记创建对象树时,运行时代码可以按此名称引用 XAML 声明的对象。

(继承自 FrameworkElement)
Opacity

获取或设置对象的不透明度的程度。

(继承自 UIElement)
OpacityTransition

获取或设置对 Opacity 属性的更改进行动画处理的 ScalarTransition。

(继承自 UIElement)
OpticalMarginAlignment

获取或设置一个值,该值指示如何修改字体以与不同大小的字体保持一致。

OpticalMarginAlignmentProperty

标识 OpticalMarginAlignment 依赖属性。

Padding

获取或设置一个值,该值指示内容区域的边界与 TextBlock 显示的内容之间的填充空间的粗细。

PaddingProperty

标识 Padding 依赖属性。

Parent

获取对象树中此 FrameworkElement 的父对象。

(继承自 FrameworkElement)
PointerCaptures

获取所有捕获的指针的集合,表示为 Pointer 值。

(继承自 UIElement)
Projection

获取或设置呈现此元素时要应用的透视投影 (三维效果) 。

(继承自 UIElement)
RenderSize

获取 UIElement 的最终呈现大小。 不建议使用 ,请参阅备注。

(继承自 UIElement)
RenderTransform

获取或设置影响 UIElement 呈现位置的转换信息。

(继承自 UIElement)
RenderTransformOrigin

获取或设置 RenderTransform 声明的任何可能的呈现转换相对于 UIElement 边界的原点。

(继承自 UIElement)
RequestedTheme

获取或设置 UIElement (使用的 UI 主题及其子元素) 用于资源确定。 使用 RequestedTheme 指定的 UI 主题可以替代应用级 RequestedTheme

(继承自 FrameworkElement)
Resources

获取本地定义的资源字典。 在 XAML 中,可以通过 XAML 隐式集合语法将资源项建立为属性元素的 frameworkElement.Resources 子对象元素。

(继承自 FrameworkElement)
Rotation

获取或设置顺时针旋转的角度(以度为单位)。 相对于 RotationAxis 和 CenterPoint 旋转。 影响元素的呈现位置。

(继承自 UIElement)
RotationAxis

获取或设置要围绕元素旋转的轴。

(继承自 UIElement)
RotationTransition

获取或设置对 Rotation 属性的更改进行动画处理的 ScalarTransition。

(继承自 UIElement)
Scale

获取或设置元素的刻度。 相对于元素的 CenterPoint 缩放。 影响元素的呈现位置。

(继承自 UIElement)
ScaleTransition

获取或设置对 Scale 属性的更改进行动画处理的 Vector3Transition。

(继承自 UIElement)
SelectedText

获取所选文本的文本范围。

SelectedTextProperty

标识 SelectedText 依赖属性。

SelectionEnd

获取 TextBlock 中所选文本的结束位置。

SelectionFlyout

获取或设置使用触摸或笔选择文本时显示的浮出控件;如果未显示浮出控件,则为 null

SelectionFlyoutProperty

标识 SelectionFlyout 依赖属性。

SelectionHighlightColor

获取或设置用于突出显示所选文本的画笔。

SelectionHighlightColorProperty

标识 SelectionHighlightColor 依赖属性。

SelectionStart

获取 TextBlock 中所选文本的起始位置。

Shadow

获取或设置元素投射的阴影效果。

(继承自 UIElement)
Style

获取或设置在布局和呈现期间为此对象应用的实例 Style

(继承自 FrameworkElement)
TabFocusNavigation

获取或设置一个值,该值修改 Tabbing 和 TabIndex 对此控件的工作方式。

(继承自 UIElement)
Tag

获取或设置可用于存储有关此对象的自定义信息的任意对象值。

(继承自 FrameworkElement)
Text

获取或设置 TextBlock 的文本内容。

TextAlignment

获取或设置一个值,该值指示文本内容的水平对齐方式。

TextAlignmentProperty

标识 TextAlignment 依赖属性。

TextDecorations

获取或设置一个值,该值指示应用于文本的修饰。

TextDecorationsProperty

标识 TextDecorations 依赖属性。

TextHighlighters

获取文本突出显示的集合。

TextLineBounds

获取或设置一个值,该值指示如何确定 TextBlock 中每行文本的行框高度。

TextLineBoundsProperty

标识 TextLineBounds 依赖属性。

TextProperty

标识 Text 依赖属性。

TextReadingOrder

获取或设置一个值,该值指示如何确定 TextBlock 的阅读顺序。

TextReadingOrderProperty

标识 TextReadingOrder 依赖属性。

TextTrimming

获取或设置在内容超出内容区域时要采用的文本剪裁行为。

TextTrimmingProperty

标识 TextTrimming 依赖属性。

TextWrapping

获取或设置 TextBlock 包装文本的方式。

TextWrappingProperty

标识 TextWrapping 依赖属性。

Transform3D

获取或设置呈现此元素时要应用的三维转换效果。

(继承自 UIElement)
TransformMatrix

获取或设置要应用于元素的转换矩阵。

(继承自 UIElement)
Transitions

获取或设置应用于 UIElementTransition 样式元素的集合。

(继承自 UIElement)
Translation

获取或设置元素的 x、y 和 z 呈现位置。

(继承自 UIElement)
TranslationTransition

获取或设置对 Translation 属性的更改进行动画处理的 Vector3Transition。

(继承自 UIElement)
Triggers

获取为 FrameworkElement 定义的动画触发器的集合。 不常用。 请参阅“备注”。

(继承自 FrameworkElement)
UIContext

获取 元素的上下文标识符。

(继承自 UIElement)
UseLayoutRounding

获取或设置一个值,该值确定对象及其可视子树的呈现是否应使用使呈现与整个像素对齐的舍入行为。

(继承自 UIElement)
VerticalAlignment

获取或设置在父对象(如面板或项控件)中组合时应用于 FrameworkElement 的垂直对齐特征。

(继承自 FrameworkElement)
Visibility

获取或设置 UIElement 的可见性。 不可见的 UIElement 不会呈现,也不会将其所需大小传达给布局。

(继承自 UIElement)
Width

获取或设置 FrameworkElement 的宽度。

(继承自 FrameworkElement)
XamlRoot

获取或设置 XamlRoot 在其中查看此元素的 。

(继承自 UIElement)
XYFocusDownNavigationStrategy

获取或设置一个值,该值指定用于确定向下导航的目标元素的策略。

(继承自 UIElement)
XYFocusKeyboardNavigation

获取或设置一个值,该值使用键盘方向箭头启用或禁用导航。

(继承自 UIElement)
XYFocusLeftNavigationStrategy

获取或设置一个值,该值指定用于确定左侧导航的目标元素的策略。

(继承自 UIElement)
XYFocusRightNavigationStrategy

获取或设置一个值,该值指定用于确定右侧导航的目标元素的策略。

(继承自 UIElement)
XYFocusUpNavigationStrategy

获取或设置一个值,该值指定用于确定向上导航的目标元素的策略。

(继承自 UIElement)

方法

AddHandler(RoutedEvent, Object, Boolean)

为指定的路由事件添加路由事件处理程序,并将该处理程序添加到当前元素的处理程序集合中。 将 handledEventsToo 指定为 true 以调用提供的处理程序,即使在其他位置处理事件也是如此。

(继承自 UIElement)
Arrange(Rect)

定位子对象并确定 UIElement 的大小。 为其子元素实现自定义布局的父对象应从其布局重写实现中调用此方法,以形成递归布局更新。

(继承自 UIElement)
ArrangeOverride(Size)

提供布局的“排列”传递的行为。 类可以重写此方法,以定义自己的“排列”传递行为。

(继承自 FrameworkElement)
CancelDirectManipulations()

取消正在进行的直接操作处理, (系统定义的平移/缩放) 包含当前 UIElement 的任何 ScrollViewer 父级。

(继承自 UIElement)
CapturePointer(Pointer)

将指针捕获设置为 UIElement。 捕获后,只有具有捕获的元素才会触发与指针相关的事件。

(继承自 UIElement)
ClearValue(DependencyProperty)

清除依赖属性的本地值。

(继承自 DependencyObject)
CopySelectionToClipboard()

将所选内容复制到 Windows 剪贴板。

FindName(String)

检索具有指定标识符名称的对象。

(继承自 FrameworkElement)
FindSubElementsForTouchTargeting(Point, Rect)

使 UIElement 子类能够公开有助于解析触摸目标的子元素。

(继承自 UIElement)
Focus(FocusState)

聚焦 TextBlock,就像它是一个常规的可聚焦控件一样。

GetAlphaMask()

返回一个掩码,该掩码将文本的 alpha 通道表示为 CompositionBrush

GetAnimationBaseValue(DependencyProperty)

返回为依赖属性建立的任何基值,该基值适用于动画未处于活动状态的情况。

(继承自 DependencyObject)
GetBindingExpression(DependencyProperty)

返回 BindingExpression ,它代表指定属性上的绑定。

(继承自 FrameworkElement)
GetChildrenInTabFocusOrder()

允许 UIElement 子类公开参与 Tab 焦点的子元素。

(继承自 UIElement)
GetValue(DependencyProperty)

DependencyObject 返回依赖属性的当前有效值。

(继承自 DependencyObject)
GoToElementStateCore(String, Boolean)

在派生类中实现时,在代码中为控件模板启用可视化树的按状态构造,而不是在控件启动时加载所有状态的 XAML。

(继承自 FrameworkElement)
InvalidateArrange()

使 UIElement 的排列状态 (布局) 无效。 失效后, UIElement 将更新其布局,这将异步发生。

(继承自 UIElement)
InvalidateMeasure()

使 UIElement 的测量状态 (布局) 无效。

(继承自 UIElement)
InvalidateViewport()

使用于计算有效视区的 UIElement视区状态失效。

(继承自 FrameworkElement)
Measure(Size)

汇报 UIElementDesiredSize。 通常,为其布局子级实现自定义布局的对象从其自己的 MeasureOverride 实现中调用此方法,以形成递归布局更新。

(继承自 UIElement)
MeasureOverride(Size)

为布局周期的“度量”传递提供行为。 类可以重写此方法以定义其自己的“Measure”传递行为。

(继承自 FrameworkElement)
OnApplyTemplate()

每当应用程序代码或内部进程 (例如重新生成布局传递) 调用 ApplyTemplate 时调用。 简单来说,这意味着在 UI 元素在应用中显示之前调用 方法。 重写此方法以影响类的默认模板后逻辑。

(继承自 FrameworkElement)
OnBringIntoViewRequested(BringIntoViewRequestedEventArgs)

BringIntoViewRequested 事件发生之前调用。

(继承自 UIElement)
OnCreateAutomationPeer()

在派生类中实现时,为 Microsoft UI 自动化基础结构返回特定于类的 AutomationPeer 实现。

(继承自 UIElement)
OnDisconnectVisualChildren()

重写此方法以实现从特定于类的内容或子属性中删除项时布局和逻辑的行为方式。

(继承自 UIElement)
OnKeyboardAcceleratorInvoked(KeyboardAcceleratorInvokedEventArgs)

在应用中处理 键盘快捷方式 (或快捷键) 时调用。 重写此方法以处理调用键盘快捷键时应用响应的方式。

(继承自 UIElement)
OnProcessKeyboardAccelerators(ProcessKeyboardAcceleratorEventArgs)

在应用中处理 键盘快捷方式 (或快捷键) 之前调用。 每当应用程序代码或内部进程调用 ProcessKeyboardAccelerators 时调用。 重写此方法以影响默认加速器处理。

(继承自 UIElement)
PopulatePropertyInfo(String, AnimationPropertyInfo)

定义可进行动画处理的属性。

(继承自 UIElement)
PopulatePropertyInfoOverride(String, AnimationPropertyInfo)

在派生类中重写时,定义可进行动画处理的属性。

(继承自 UIElement)
ReadLocalValue(DependencyProperty)

如果设置了本地值,则返回依赖属性的本地值。

(继承自 DependencyObject)
RegisterPropertyChangedCallback(DependencyProperty, DependencyPropertyChangedCallback)

注册通知函数,用于侦听此 DependencyObject 实例上对特定 DependencyProperty 的更改。

(继承自 DependencyObject)
ReleasePointerCapture(Pointer)

释放指针捕获,以便通过此 UIElement 捕获一个特定指针。

(继承自 UIElement)
ReleasePointerCaptures()

释放此元素持有的所有指针捕获。

(继承自 UIElement)
RemoveHandler(RoutedEvent, Object)

从此 UIElement 中删除指定的路由事件处理程序。 通常,有问题的处理程序是由 AddHandler 添加的。

(继承自 UIElement)
Select(TextPointer, TextPointer)

TextBlock 中选择一个文本范围。

SelectAll()

选择 TextBlock 中的全部内容。

SetBinding(DependencyProperty, BindingBase)

使用提供的绑定对象将绑定附加到 FrameworkElement

(继承自 FrameworkElement)
SetValue(DependencyProperty, Object)

设置 DependencyObject 上依赖属性的本地值。

(继承自 DependencyObject)
StartAnimation(ICompositionAnimationBase)

开始元素上的指定动画。

(继承自 UIElement)
StartBringIntoView()

向 XAML 框架发起请求,以将元素引入其包含的任何可滚动区域内的视图。

(继承自 UIElement)
StartBringIntoView(BringIntoViewOptions)

启动对 XAML 框架的请求,以使用指定的选项将元素引入视图。

(继承自 UIElement)
StartDragAsync(PointerPoint)

启动拖放操作。

(继承自 UIElement)
StopAnimation(ICompositionAnimationBase)

停止元素上的指定动画。

(继承自 UIElement)
TransformToVisual(UIElement)

返回一个转换对象,该对象可用于将 坐标从 UIElement 转换为指定对象。

(继承自 UIElement)
TryInvokeKeyboardAccelerator(ProcessKeyboardAcceleratorEventArgs)

尝试通过搜索 UIElement 的整个可视化树来 (或快捷键) 调用键盘快捷方式。

(继承自 UIElement)
UnregisterPropertyChangedCallback(DependencyProperty, Int64)

取消以前通过调用 RegisterPropertyChangedCallback 注册的更改通知。

(继承自 DependencyObject)
UpdateLayout()

确保针对布局正确更新 UIElement 的子对象的所有位置。

(继承自 UIElement)

事件

AccessKeyDisplayDismissed

在不应再显示访问密钥时发生。

(继承自 UIElement)
AccessKeyDisplayRequested

当用户请求显示访问密钥时发生。

(继承自 UIElement)
AccessKeyInvoked

当用户完成访问密钥序列时发生。

(继承自 UIElement)
ActualThemeChanged

在 ActualTheme 属性值更改时发生。

(继承自 FrameworkElement)
BringIntoViewRequested

在此元素或其后代之一上调用 StartBringIntoView 时发生。

(继承自 UIElement)
CharacterReceived

输入队列接收到单个组合字符时发生。

(继承自 UIElement)
ContextCanceled

当上下文输入手势继续转换为操作手势时发生,以通知元素不应打开上下文浮出控件。

(继承自 UIElement)
ContextMenuOpening

当系统处理显示上下文菜单的交互时发生。

ContextRequested

当用户完成上下文输入手势(例如右键单击)时发生。

(继承自 UIElement)
DataContextChanged

FrameworkElement.DataContext 属性的值更改时发生。

(继承自 FrameworkElement)
DoubleTapped

当此元素的命中测试区域发生其他未经处理的 DoubleTap 交互时发生。

(继承自 UIElement)
DragEnter

当输入系统报告具有此元素作为目标的基础拖动事件时发生。

(继承自 UIElement)
DragLeave

当输入系统报告具有此元素作为原点的基础拖动事件时发生。

(继承自 UIElement)
DragOver

在输入系统报告出现以此元素为可能放置目标的基础拖动事件时发生。

(继承自 UIElement)
DragStarting

在启动拖动操作时发生。

(继承自 UIElement)
Drop

在输入系统报告出现将此元素作为放置目标的基础放置事件时发生。

(继承自 UIElement)
DropCompleted

结束此元素作为源的拖放操作时发生。

(继承自 UIElement)
EffectiveViewportChanged

FrameworkElement的有效视区 更改时发生。

(继承自 FrameworkElement)
GettingFocus

UIElement 接收焦点之前发生。 此事件是同步引发的,以确保在事件冒泡时不会移动焦点。

(继承自 UIElement)
GotFocus

UIElement 收到焦点时发生。 此事件以异步方式引发,因此焦点可以在冒泡完成之前再次移动。

(继承自 UIElement)
Holding

在此元素的命中测试区域上发生未处理的 保留 交互时发生。

(继承自 UIElement)
IsTextTrimmedChanged

IsTextTrimmed 属性值更改时发生。

KeyDown

UIElement 具有焦点时按下键盘键时发生。

(继承自 UIElement)
KeyUp

UIElement 具有焦点时释放键盘键时发生。

(继承自 UIElement)
LayoutUpdated

当可视化树的布局更改时发生,因为布局相关的属性更改值或刷新布局的其他操作。

(继承自 FrameworkElement)
Loaded

在已构造 FrameworkElement 并将其添加到对象树中并准备好交互时发生。

(继承自 FrameworkElement)
Loading

在开始加载 FrameworkElement 时发生。

(继承自 FrameworkElement)
LosingFocus

UIElement 失去焦点之前发生。 此事件是同步引发的,以确保在事件冒泡时不会移动焦点。

(继承自 UIElement)
LostFocus

UIElement 失去焦点时发生。 此事件以异步方式引发,因此焦点可以在冒泡完成之前再次移动。

(继承自 UIElement)
ManipulationCompleted

UIElement 上的操作完成时发生。

(继承自 UIElement)
ManipulationDelta

当输入设备在操作期间更改位置时发生。

(继承自 UIElement)
ManipulationInertiaStarting

在输入设备在操作期间与 UIElement 对象失去联系和延迟开始时发生。

(继承自 UIElement)
ManipulationStarted

在输入设备在 UIElement 上开始操作时发生。

(继承自 UIElement)
ManipulationStarting

在首次创建操作处理器时发生。

(继承自 UIElement)
NoFocusCandidateFound

当用户尝试通过制表键或方向箭头 (移动焦点) ,但焦点不会移动时发生,因为移动方向上找不到焦点候选项。

(继承自 UIElement)
PointerCanceled

当进行接触的指针异常失去接触时发生。

(继承自 UIElement)
PointerCaptureLost

当此元素以前持有的指针捕获移动到另一个元素或其他位置时发生。

(继承自 UIElement)
PointerEntered

当指针进入此元素的命中测试区域时发生。

(继承自 UIElement)
PointerExited

当指针离开此元素的命中测试区域时发生。

(继承自 UIElement)
PointerMoved

当指针在指针停留在此元素的命中测试区域内时移动时发生。

(继承自 UIElement)
PointerPressed

当指针设备在此元素中启动 Press 操作时发生。

(继承自 UIElement)
PointerReleased

在释放之前启动 按下 操作的指针设备时发生,同时在此元素中。 请注意, 不保证按下 操作的结尾会触发 PointerReleased 事件;可能会触发其他事件。 有关详细信息,请参阅备注。

(继承自 UIElement)
PointerWheelChanged

在指针滚轮的增量值更改时发生。

(继承自 UIElement)
PreviewKeyDown

UIElement 具有焦点时按下键盘键时发生。

(继承自 UIElement)
PreviewKeyUp

UIElement 具有焦点时释放键盘键时发生。

(继承自 UIElement)
ProcessKeyboardAccelerators

按下 键盘快捷方式 (或快捷键) 时发生。

(继承自 UIElement)
RightTapped

当指针位于 元素上时发生右点击输入刺激时发生。

(继承自 UIElement)
SelectionChanged

在文本选择改变时发生。

SizeChanged

ActualHeightActualWidth 属性更改 FrameworkElement 上的值时发生。

(继承自 FrameworkElement)
Tapped

在此元素的命中测试区域上发生未经处理的 点击 交互时发生。

(继承自 UIElement)
Unloaded

当此对象不再连接到main对象树时发生。

(继承自 FrameworkElement)

适用于

另请参阅