TextElement class

Applies to Windows and Windows Phone

An abstract class used as the base class for the also-abstract Block and Inline classes. TextElement supports common API for classes involved in the XAML text object model, such as properties that control text size, font families and so on.

Inheritance

Object
  DependencyObject
    TextElement

Syntax


public class TextElement : DependencyObject

Attributes

[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]
[WebHostHidden()]

Members

The TextElement class has these types of members:

Methods

The TextElement class has these methods. It also inherits methods from the Object class.

MethodDescription
ClearValue Clears the local value of a dependency property. (Inherited from DependencyObject)
FindName Retrieves an object in the object model / runtime object graph by referencing the object's x:Name or Name attribute value.
GetAnimationBaseValue Returns any base value established for a dependency property, which would apply in cases where an animation is not active. (Inherited from DependencyObject)
GetValue Returns the current effective value of a dependency property from a DependencyObject. (Inherited from DependencyObject)
OnDisconnectVisualChildren Override this method to implement how layout and logic should behave when items are removed from a class-specific content or child property.
ReadLocalValue Returns the local value of a dependency property, if a local value is set. (Inherited from DependencyObject)
SetValue Sets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject)

 

Properties

The TextElement class has these properties.

PropertyAccess typeDescription

CharacterSpacing

Read/writeGets or sets the uniform spacing between characters, in units of 1/1000 of an em.

CharacterSpacingProperty

Read-onlyIdentifies the CharacterSpacing dependency property.

ContentEnd

Read-onlyGets a TextPointer that represents the end of the content in the element.

ContentStart

Read-onlyGets a TextPointer that represents the start of content in the element.

Dispatcher

Read-onlyGets the CoreDispatcher that this object is associated with. (Inherited from DependencyObject)

ElementEnd

Read-onlyGets a TextPointer that represents the position just after the end of the element.

ElementStart

Read-onlyGets a TextPointer that represents the position just before the start of the element.

FontFamily

Read/writeGets or sets the preferred top-level font family for the content of the element.

FontFamilyProperty

Read-onlyIdentifies the FontFamily dependency property.

FontSize

Read/writeGets or sets the font size for the content of the element.

FontSizeProperty

Read-onlyIdentifies the FontSize dependency property.

FontStretch

Read/writeGets or sets the glyph width of the font in a family to select.

FontStretchProperty

Read-onlyIdentifies the FontStretch dependency property.

FontStyle

Read/writeGets or sets the font style for the content in this element.

FontStyleProperty

Read-onlyIdentifies the FontStyle dependency property.

FontWeight

Read/writeGets or sets the top-level font weight to select from the font family for the content in this element.

FontWeightProperty

Read-onlyIdentifies the FontWeight dependency property.

Foreground

Read/writeGets or sets the Brush to apply to the content in this element.

ForegroundProperty

Read-onlyIdentifies the Foreground dependency property.

IsTextScaleFactorEnabled

Read/writeGets or sets whether automatic text enlargement, to reflect the system text size setting, is enabled.

IsTextScaleFactorEnabledProperty

Read-onlyIdentifies the IsTextScaleFactorEnabled dependency property.

Language

Read/writeGets or sets localization/globalization language information that applies to a TextElement.

LanguageProperty

Read-onlyIdentifies the Language dependency property.

Name

Read-onlyGets or sets a unique identification for the object. Name can only be set from initial parsing of XAML.

 

Remarks

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.

Note  

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 APIs 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.

Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml.Documents
Windows::UI::Xaml::Documents [C++]

Metadata

Windows.winmd

See also

DependencyObject
Block
Inline
Typography
Quickstart: Displaying text

 

 

Show:
© 2014 Microsoft