public : class TextElement : DependencyObject
struct winrt::Windows::UI::Xaml::Documents::TextElement : DependencyObject
public class TextElement : DependencyObject
Public Class TextElement Inherits DependencyObject
Windows 10 requirements
Windows 10 (introduced v10.0.10240.0)
Windows.Foundation.UniversalApiContract (introduced v1)
The various properties defined by TextElement support a common API for classes involved in the XAML text object model. Here's a list of the most commonly used properties:
By setting TextElement properties, you can apply common text formatting properties to text, both in blocks and in inlines. There are also additional ways to format text, but these aren't directly supported by TextElement. Instead, you can use the attached properties of the Typography class. Typography attached properties typically support advanced typographic features or conventions, such as accessing typographic features defined at the font level that are not necessarily supported by all fonts. For example, you could set Typography.Variants as an attached property on any text block or inline, and this would influence the font-variants behavior as enabled by the particular font you chose for setting FontFamily on that text element.
TextElement doesn't inherently define a connection point to a XAML visual tree. In other words a TextElement defines text and text object model within that text, but it doesn't yet enable the display of that text within a UI. For that, you need to use one of the controls or elements that are descendants of UIElement and can be connected to the XAML tree and the root visual of your app window. There are two such elements in the Windows Runtime:
- TextBlock: Supports a text object model of inlines only with its Inlines collection.
- RichTextBlock: Supports a block text object model with its Blocks collection. The blocks can contain blocks and inlines.
PasswordBox, RichEditBox and TextBox don't support a text object model that's based on TextElement. RichEditBox does enable programmatic access to a different text object model through the ITextDocument interface.
TextElement defines API that support examining the text object model as programming objects after the XAML is parsed. In particular TextElement implements Name and Language, which parallel properties of the same name on FrameworkElement. TextElement also implements FindName (a utility method for finding objects at run time based on how Name was set in initial XAML), and OnDisconnectVisualChildren (for advanced scenarios and designer support).
TextElement has four properties that provide access to TextPointer objects from within text. These properties are: ContentStart, ContentEnd, ElementStart, ElementEnd. A Windows Runtime TextPointer object gives you an entry point for traversal of content. For more info, see TextPointer.
TextElement is a class derived from DependencyObject. That means it can define dependency properties, and each of the read-write properties of TextElement is a dependency property, with its property identifier also defined by TextElement. For more info on what dependency properties enable, see Dependency properties overview.
TextElement derived classes
TextElement is the parent class for two derived classes that split the text object model into two text usage conventions: Block, and Inline. Block and Inline are both considered base classes (you don't typically see a
<Block> tag in XAML) and exist in the hierarchy mainly to be the parent class of other practical text elements. For example, Block is the parent class of Paragraph. For more info on how to use block and inline elements, see Quickstart: Displaying text.
|Windows version||SDK version||Value added|
|AccessKeyDisplayDismissed AccessKeyDisplayDismissed AccessKeyDisplayDismissed AccessKeyDisplayDismissed||
Occurs when the access key sequence is complete to notify controls that they should hide access key visuals.
|AccessKeyDisplayRequested AccessKeyDisplayRequested AccessKeyDisplayRequested AccessKeyDisplayRequested||
Occurs when the access key sequence is started to notify controls that they should show access key visuals.
|AccessKeyInvoked AccessKeyInvoked AccessKeyInvoked AccessKeyInvoked||
Occurs when a user completes an access key sequence to notify the element that the access key action should be invoked.