RichTextBlock 类

定义

表示支持格式化文本、超链接、内联图像和其他丰富内容的富文本显示容器。 RichTextBlock 支持内置溢出模型。

public ref class RichTextBlock 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="Blocks")]
class RichTextBlock 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="Blocks")]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
class RichTextBlock 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="Blocks")]
public sealed class RichTextBlock : 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="Blocks")]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
public sealed class RichTextBlock : FrameworkElement
Public NotInheritable Class RichTextBlock
Inherits FrameworkElement
<RichTextBlock .../>
-or-
<RichTextBlock ...>
  blocksContent
</RichTextBlock>
继承
Object Platform::Object IInspectable DependencyObject UIElement FrameworkElement RichTextBlock
属性

Windows 要求

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

示例

提示

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

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

此示例演示启用了文本选择和文本换行的 RichTextBlock。

在 XAML 中,内容元素的创建是隐式的,因此可以直接将文本添加到 Paragraph 元素,将 Paragraph 直接添加到 RichTextBlock 元素。

在代码中,必须显式创建每个 Run 元素,设置其 Text 属性,并将其添加到 Paragraph.Inlines 集合。 然后,将每个 Paragraph 添加到 RichTextBlock.Blocks 集合。

<RichTextBlock IsTextSelectionEnabled="True" TextWrapping="Wrap" Width="200" >
    <Paragraph>
        This is some sample text to show the wrapping behavior.
    </Paragraph>
</RichTextBlock>
// Create a RichTextBlock, a Paragraph and a Run.
RichTextBlock richTextBlock = new RichTextBlock();
Paragraph paragraph = new Paragraph();
Run run = new Run();

// Customize some properties on the RichTextBlock.
richTextBlock.IsTextSelectionEnabled = true;
richTextBlock.TextWrapping = TextWrapping.Wrap;
run.Text = "This is some sample text to show the wrapping behavior.";
richTextBlock.Width = 200;

// Add the Run to the Paragraph, the Paragraph to the RichTextBlock.
paragraph.Inlines.Add(run);
richTextBlock.Blocks.Add(paragraph);

// Add the RichTextBlock to the visual tree (assumes stackPanel is decalred in XAML).
stackPanel.Children.Add(richTextBlock);

本示例演示了一个 RichTextBlock,其中包含对单次文本的 FontWeightFontFamilyFontStyleForegroundSelectionHighlightColor 的自定义。

在 XAML 中,内容元素的创建是隐式的,因此可以直接将文本添加到 Paragraph 元素,将 Paragraph 直接添加到 RichTextBlock 元素。

在代码中,必须显式创建每个 Run 元素,设置其 Text 属性,并将其添加到 Paragraph.Inlines 集合。 然后,将每个 Paragraph 添加到 RichTextBlock.Blocks 集合。

<RichTextBlock IsTextSelectionEnabled="True" SelectionHighlightColor="Pink" 
               FontWeight="Light" FontFamily="Arial" FontStyle="Italic" 
               Foreground="Blue">
    <Paragraph>
        This is some sample text to demonstrate some properties.
    </Paragraph>
</RichTextBlock>
// Create a RichTextBlock, a Paragraph and a Run.
RichTextBlock richTextBlock = new RichTextBlock();
Paragraph paragraph = new Paragraph();
Run run = new Run();

// Customize some properties on the RichTextBlock.
richTextBlock.IsTextSelectionEnabled = true;
richTextBlock.SelectionHighlightColor = new SolidColorBrush(Windows.UI.Colors.Pink);
richTextBlock.Foreground = new SolidColorBrush(Windows.UI.Colors.Blue);
richTextBlock.FontWeight = Windows.UI.Text.FontWeights.Light;
richTextBlock.FontFamily = new FontFamily("Arial");
richTextBlock.FontStyle = Windows.UI.Text.FontStyle.Italic;
run.Text = "This is some sample text to demonstrate some properties.";

//Add the Run to the Paragraph, the Paragraph to the RichTextBlock.
paragraph.Inlines.Add(run);
richTextBlock.Blocks.Add(paragraph);

// Add the RichTextBlock to the visual tree (assumes stackPanel is decalred in XAML).
stackPanel.Children.Add(richTextBlock);

此示例演示了一个 RichTextBlock,其中包含用于不同文本运行的 FontWeightFontFamilyFontStyleForegroundSelectionHighlightColor 的自定义项。

在 XAML 中,内容元素的创建是隐式的,因此可以直接将文本添加到 Paragraph 元素,将 Paragraph 直接添加到 RichTextBlock 元素。

在代码中,必须显式创建每个 Run 元素,设置其 Text 属性,并将其添加到 Paragraph.Inlines 集合。 然后,将每个 Paragraph 添加到 RichTextBlock.Blocks 集合。

<RichTextBlock IsTextSelectionEnabled="True" SelectionHighlightColor="Pink" FontFamily="Arial"  >
    <Paragraph>
        <Run Foreground="Blue" FontWeight="Light" Text="This is some" ></Run>
        <Span FontWeight="SemiBold">
            <Run FontStyle="Italic">sample text to</Run>
            <Run Foreground="Red">demonstrate some properties.</Run>
        </Span>
    </Paragraph>
</RichTextBlock>
RichTextBlock richTextBlock = new RichTextBlock();
richTextBlock.IsTextSelectionEnabled = true;
richTextBlock.SelectionHighlightColor = new SolidColorBrush(Windows.UI.Colors.Pink);
richTextBlock.FontFamily = new FontFamily("Arial");

Paragraph paragraph = new Paragraph();
Run run = new Run();
run.Foreground = new SolidColorBrush(Windows.UI.Colors.Blue);
run.FontWeight = Windows.UI.Text.FontWeights.Light;
run.Text = "This is some";

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

Run run1 = new Run();
run1.FontStyle = Windows.UI.Text.FontStyle.Italic;
run1.Text = " sample text to ";

Run run2 = new Run();
run2.Foreground = new SolidColorBrush(Windows.UI.Colors.Red);
run2.Text = " demonstrate some properties";

span.Inlines.Add(run1);
span.Inlines.Add(run2);
paragraph.Inlines.Add(run);
paragraph.Inlines.Add(span);
richTextBlock.Blocks.Add(paragraph);

// Add the RichTextBlock to the visual tree (assumes stackPanel is decalred in XAML).
stackPanel.Children.Add(richTextBlock);

此处,RichTextBlock 以 RichTextBlockOverflow 元素为目标,以创建多列文本布局。 然后,第一个 RichTextBlockOverflow 元素面向接收其内容溢出的第二个 RichTextBlockOverflow 元素。 文本溢出计算方式的控制布局因素是父网格的受约束的宽度高度,以及将网格划分为三个高度/宽度为 300 像素的相等列的 ColumnDefinition 设置。 Overflow 还受 FontSize 和许多其他文本格式属性的影响,这些属性会更改文本中的字符。

<Grid x:Name="columnGrid" Background="White" Width="900" Height="300">
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <RichTextBlock Grid.Column="0" IsTextSelectionEnabled="True" TextAlignment="Justify" 
                   OverflowContentTarget="{Binding ElementName=firstOverflowContainer}" 
                   TextIndent="12"
                   FontSize="12" FontFamily="Segoe UI" Foreground="#2a2a2a" Margin="20,0">
        <Paragraph>
            <Bold><Span Foreground="DarkSlateBlue" FontSize="16">Lorem ipsum dolor sit amet</Span></Bold>, consectetur adipiscing elit. Sed ac mi ipsum. Phasellus vel malesuada mauris. Donec pharetra, enim sit amet mattis tincidunt, felis nisi semper lectus, vel porta diam nisi in augue. Pellentesque lacus tortor, aliquam et faucibus id, rhoncus ut justo. Sed id lectus odio, eget pulvinar diam. Suspendisse eleifend ornare libero, in luctus purus aliquet non. Sed interdum, sem vitae rutrum rhoncus, felis ligula ultrices sem, in eleifend eros ante id neque. Vivamus quam lorem, varius vitae porta mollis, placerat quis est. Aenean eget sagittis massa. Sed tellus turpis, ullamcorper eget imperdiet vel, faucibus vel nisl. Nunc sed suscipit quam. Vivamus convallis faucibus dignissim. Fusce sollicitudin, quam vel cursus mattis, nisl velit tristique sapien, ac vestibulum ante arcu a nisl. Vestibulum commodo gravida ante at tincidunt. Vestibulum in ornare nunc. Nullam ut lorem vitae dui placerat lacinia sit amet a arcu. Nulla sit amet odio nisi. Praesent erat urna, venenatis ac adipiscing vel, congue at lectus. Proin ac metus at quam luctus ultricies.
        </Paragraph>
        <Paragraph>
            <Italic>This is an inline image.</Italic>
            <InlineUIContainer>
                <Border Background="Black">
                    <Image Source="Assets/SmallLogo.png" Height="30" Width="30"/>
                </Border>
            </InlineUIContainer> 
            Nam vitae ligula non ligula suscipit semper. Duis sed nulla metus, id hendrerit velit. Curabitur dolor purus, bibendum eu cursus lacinia, interdum vel augue. Aenean euismod eros et sapien vehicula dictum. Duis ullamcorper, turpis nec feugiat tincidunt, dui erat luctus risus, aliquam accumsan lacus est vel quam. Nunc lacus massa, varius eget accumsan id, congue sed orci. Duis dignissim hendrerit egestas. Proin ut turpis magna, sit amet porta erat. Nunc semper metus nec magna imperdiet nec vestibulum dui fringilla. Sed sed ante libero, nec porttitor mi. Ut luctus, neque vitae placerat egestas, urna leo auctor magna, sit amet ultricies ipsum felis quis sapien. Proin eleifend varius dui, at vestibulum nunc consectetur nec. Mauris nulla elit, ultrices a sodales non, aliquam ac est. Quisque sit amet risus nulla. Quisque vestibulum posuere velit, vitae vestibulum eros scelerisque sit amet. In in risus est, at laoreet dolor. Nullam aliquet pellentesque convallis. Ut vel tincidunt nulla. Mauris auctor tincidunt auctor.
        </Paragraph>
    </RichTextBlock>
    <RichTextBlockOverflow x:Name="firstOverflowContainer" Grid.Column="1" Margin="20,0"
                           OverflowContentTarget="{Binding ElementName=secondOverflowContainer}"/>
    <RichTextBlockOverflow x:Name="secondOverflowContainer" Grid.Column="2" Margin="20,0"/>
</Grid>

注解

提示

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

RichTextBlock 控件显示只读文本,并提供多个高级文本布局功能。 如果需要对段落、内联 UI 元素或溢出文本的支持,请使用 RichTextBlock。

TextBlock 提供更简单的内容模型,因此通常更易于使用,并且它可以提供比 RichTextBlock 更好的文本呈现性能。 它还提供许多用于自定义文本呈现方式的相同格式设置选项。 但是,RichTextBlock 提供了 一些 TextBlock 未提供的独特功能。

有关详细信息和示例,请参阅 RichTextBlock 控件指南

段落和格式设置

RichTextBlock 的内容属性是基于 Paragraph 元素的 Blocks 属性。 通过设置 TextIndent 属性设置段落缩进。

可以使用 Text 元素和 Typography 类的附加属性将字符和段落格式应用于 RichTextBlock 中的文本。 例如,可以对控件中文本的任何部分应用 加粗斜体下划线

内联 UI 元素

可以在 RichTextBlock 的内容中使用 InlineUIContainer 在文本中嵌入派生自 UIElement 的元素(如图像)。

溢出内容

可以使用 RichTextBlock 和 RichTextBlockOverflow 元素来创建高级页面布局,例如多列文本。 RichTextBlockOverflow 元素的内容始终来自 RichTextBlock 元素。 通过将 RichTextBlockOverflow 元素设置为 RichTextBlock 或其他 RichTextBlockOverflowOverflowContentTarget 来链接这些元素。

字体回退

RichTextBlock 的默认 FontFamily 为 Segoe UI,默认 FontSize 为 15 个与设备无关的像素, (DIP) 。 默认情况下,RichTextBlock 利用字体回退机制来显示未包含在指定字体中的字形。 如果 RichTextBlock 中所需的字形在指定字体中不可用,则字体回退机制会浏览系统上的字体列表,以尝试以其他字体显示所需的字符。

版本历史记录

Windows 版本 SDK 版本 已添加值
1703 15063 TextDecorations
1709 16299 HorizontalTextAlignment
1709 16299 IsTextTrimmed
1709 16299 IsTextTrimmedChanged
1709 16299 TextHighlighters
1809 17763 CopySelectionToClipboard
1809 17763 SelectionFlyout

构造函数

RichTextBlock()

初始化 RichTextBlock 类的新实例。

属性

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)
Blocks

获取 RichTextBlock 的内容。

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

获取一个 TextPointer ,它指示 RichTextBlock 中内容的结束。

ContentStart

获取一个 TextPointer ,它指示 RichTextBlock 中内容的开头。

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

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

(继承自 FrameworkElement)
FocusVisualPrimaryThickness

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

(继承自 FrameworkElement)
FocusVisualSecondaryBrush

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

(继承自 FrameworkElement)
FocusVisualSecondaryThickness

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

(继承自 FrameworkElement)
FontFamily

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

FontFamilyProperty

标识 FontFamily 依赖属性。

FontSize

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

FontSizeProperty

标识 FontSize 依赖属性。

FontStretch

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

FontStretchProperty

标识 FontStretch 依赖属性。

FontStyle

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

FontStyleProperty

标识 FontStyle 依赖属性。

FontWeight

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

FontWeightProperty

标识 FontWeight 依赖属性。

Foreground

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

ForegroundProperty

标识 前台 依赖属性。

HasOverflowContent

获取一个值,该值指示 RichTextBlock 是否具有超出其边界的内容,该内容可为 OverflowContentTarget 元素提供内容。

HasOverflowContentProperty

标识 HasOverflowContent 依赖属性。

Height

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

(继承自 FrameworkElement)
HighContrastAdjustment

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

(继承自 UIElement)
HorizontalAlignment

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

(继承自 FrameworkElement)
HorizontalTextAlignment

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

HorizontalTextAlignmentProperty

标识 HorizontalTextAlignment 依赖属性。

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

获取或设置一个值,该值确定是否可以选择 RichTextBlock 的文本内容用于剪贴板或拖动目的,或者用于指示所选文本的 UI 样式更改。

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

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

LineStackingStrategyProperty

标识 LineStackingStrategy 依赖属性。

ManipulationMode

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

(继承自 UIElement)
Margin

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

(继承自 FrameworkElement)
MaxHeight

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

(继承自 FrameworkElement)
MaxLines

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

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 依赖属性。

OverflowContentTarget

获取或设置对 RichTextBlockOverflow 的引用,此 RichTextBlockOverflow 是来自此 RichTextBlock 的任何文本溢出的链接目标。

OverflowContentTargetProperty

标识 OverflowContentTarget 依赖属性。

Padding

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

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 隐式集合语法将资源项建立为 property 元素的 frameworkElement.Resources 子对象元素。

(继承自 FrameworkElement)
Rotation

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

(继承自 UIElement)
RotationAxis

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

(继承自 UIElement)
RotationTransition

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

(继承自 UIElement)
Scale

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

(继承自 UIElement)
ScaleTransition

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

(继承自 UIElement)
SelectedText

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

SelectedTextProperty

标识 SelectedText 依赖属性。

SelectionEnd

获取 RichTextBlock 中选择的文本的结束位置。

SelectionFlyout

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

SelectionFlyoutProperty

标识 SelectionFlyout 依赖属性。

SelectionHighlightColor

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

SelectionHighlightColorProperty

标识 SelectionHighlightColor 依赖属性。

SelectionStart

获取 RichTextBlock 中选择的文本的起始位置。

Shadow

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

(继承自 UIElement)
Style

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

(继承自 FrameworkElement)
TabFocusNavigation

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

(继承自 UIElement)
Tag

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

(继承自 FrameworkElement)
TextAlignment

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

TextAlignmentProperty

标识 TextAlignment 依赖属性。

TextDecorations

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

TextDecorationsProperty

标识 TextDecorations 依赖属性。

TextHighlighters

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

TextIndent

获取或设置 RichTextBlock 中每个段落中第一行文本的缩进。

TextIndentProperty

标识 TextIndent 依赖属性。

TextLineBounds

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

TextLineBoundsProperty

标识 TextLineBounds 依赖属性。

TextReadingOrder

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

TextReadingOrderProperty

标识 TextReadingOrder 依赖属性。

TextTrimming

获取或设置一个值,该值指示文本溢出内容区域时如何剪裁。

TextTrimmingProperty

标识 TextTrimming 依赖属性。

TextWrapping

获取或设置一个值,该值指示当文本行超出 RichTextBlock 的可用宽度时是否发生文本换行。

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)

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

(继承自 FrameworkElement)
CancelDirectManipulations()

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

(继承自 UIElement)
CapturePointer(Pointer)

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

(继承自 UIElement)
ClearValue(DependencyProperty)

清除依赖属性的本地值。

(继承自 DependencyObject)
CopySelectionToClipboard()

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

FindName(String)

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

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

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

(继承自 UIElement)
Focus(FocusState)

聚焦 RichTextBlock,就像它是一个传统可聚焦的控件一样。

GetAnimationBaseValue(DependencyProperty)

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

(继承自 DependencyObject)
GetBindingExpression(DependencyProperty)

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

(继承自 FrameworkElement)
GetChildrenInTabFocusOrder()

使 UIElement 子类能够公开参与 Tab 焦点的子元素。

(继承自 UIElement)
GetPositionFromPoint(Point)

通过命中测试文本显示区域内的特定,从 RichTextBlock 返回 TextPointer 文本引用。

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)

RichTextBlock 中选择一个文本范围。

SelectAll()

选择 RichTextBlock 中的全部内容。

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)

适用于

另请参阅