Windows Dev Center

Span class

Groups other Inline content elements. Parent class for Bold, Hyperlink, Italic and Underline.

Inheritance

Object
  DependencyObject
    TextElement
      Inline
        Span

Syntax


public class Span : Inline


<Span .../>
-or-
<Span ...>
  oneOrMoreInlines
</Span>
-or-
<Span ...>
  mixedContent
</Span>

XAML Values

oneOrMoreInlines

One or more elements that derive from the Inline type. Elements declared here become items in the Inlines collection.

mixedContent

A mixture of inner text and elements that derive from the Inline type.

Members

The Span class has these types of members:

Constructors

The Span class has these constructors.

ConstructorDescription
Span Initializes a new instance of the Span class.

 

Methods

The Span 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. (Inherited from TextElement)
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. (Inherited from TextElement)
ReadLocalValue Returns the local value of a dependency property, if a local value is set. (Inherited from DependencyObject)
RegisterPropertyChangedCallback Registers an instance-specific property value for a property-changed notification that comes from the core property system. (Inherited from DependencyObject)
SetValue Sets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject)
UnregisterPropertyChangedCallback Cancels a change notification that was previously registered by calling RegisterPropertyChangedCallback. (Inherited from DependencyObject)

 

Properties

The Span class has these properties.

PropertyAccess typeDescription

CharacterSpacing

Read/writeGets or sets the uniform spacing between characters, in units of 1/1000 of an em. (Inherited from TextElement)

ContentEnd

Read-onlyGets a TextPointer that represents the end of the content in the element. (Inherited from TextElement)

ContentStart

Read-onlyGets a TextPointer that represents the start of content in the element. (Inherited from TextElement)

Dispatcher

Read-onlyGets the CoreDispatcher that this object is associated with. The CoreDispatcher represents a facility that can access the DependencyObject on the UI thread even if the code is initiated by a non-UI thread. (Inherited from DependencyObject)

ElementEnd

Read-onlyGets a TextPointer that represents the position just after the end of the element. (Inherited from TextElement)

ElementStart

Read-onlyGets a TextPointer that represents the position just before the start of the element. (Inherited from TextElement)

FontFamily

Read/writeGets or sets the preferred top-level font family for the content of the element. (Inherited from TextElement)

FontSize

Read/writeGets or sets the font size for the content of the element. (Inherited from TextElement)

FontStretch

Read/writeGets or sets the glyph width of the font in a family to select. (Inherited from TextElement)

FontStyle

Read/writeGets or sets the font style for the content in this element. (Inherited from TextElement)

FontWeight

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

Foreground

Read/writeGets or sets the Brush to apply to the content in this element. (Inherited from TextElement)

Inlines

Read/writeGets an InlineCollection containing the top-level inline elements that include the contents of Span.

IsTextScaleFactorEnabled

Read/writeGets or sets whether automatic text enlargement, to reflect the system text size setting, is enabled. (Inherited from TextElement)

Language

Read/writeGets or sets localization/globalization language information that applies to a TextElement. (Inherited from TextElement)

Name

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

 

Remarks

You can use Span as an object element in XAML to enclose text. This enables a similar usage to how you might use the span tag in HTML. For this usage you'd set the attributes that are supported by TextElement such as FontSize or FontFamily, so that you can apply these text formatting decisions to the enclosed span of text. Run has similar functionality of applying TextElement properties to a range of text, but Run doesn't support mixed content (its Run.Text XAML content property can only contain text, not mixed content and further inlines).

Span supports mixed content if you set the content in XAML. What this means is that you can mix Inline tags such as Run, Bold and so on with XAML text content (plain text), with no restrictions on the order in which tags versus text must appear. All text, whether plain text or as enclosed in an Inline tag, renders in the order that the text is defined in the mixed content. For example, this is legal XAML:


<RichTextBlock>
  <Paragraph>
    <Span>This is <Bold>mixed content</Bold> with multiple text areas <Italic> and inlines</Italic>.</Span>
  </Paragraph>
</RichTextBlock>

When mixed content is parsed from XAML, and the text object model is examined at run time, any text area that came from the plain text generates a Run object at the appropriate reading-order position in the InlineCollection collection class that enables run-time access. That Run element contains the text but otherwise has no properties set.

Note  Placing XAML content whether tags or text directly within a Span element is supported because Span denotes that its Inlines property is the XAML content property. For more info on XAML content properties, see "XAML content properties" section of Basic XAML syntax guide.

Span elements are typically used as elements within an InlineCollection, either as child elements of a Paragraph (becomes part of Paragraph.Inlines) or as the content of another Span (becomes part of Span.Inlines).

Span derived classes

Span is the parent class for several derived classes that define an inline text region with a particular formatting convention:

Hyperlink enables a click behavior that navigates to the NavigateUri. The other Span derived classes can be thought of as class-specific decorations to the text and don't otherwise add interaction.

Requirements (Windows 10 device family)

Device family

Universal

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

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

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

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

Attributes

[ContentProperty("Name=Inlines")]
[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]
[WebHostHidden()]

See also

Object
Inline
Paragraph

 

 

Show:
© 2015 Microsoft