Span Span Span Class

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

Syntax

Declaration

public class Spanpublic class SpanPublic Class Span
<Span .../>
-or-
<Span ...>
  oneOrMoreInlines
</Span>
-or-
<Span ...>
  mixedContent
</Span>

Inheritance Hierarchy

Inherited Members

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Remarks

You can use Span as an object element in XAML to enclose text. This enables a similar usage to how you might use thespan 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 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: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 XAML syntax guide.

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

Span derived classes

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

Constructors summary

Initializes a new instance of the Span class.

Properties summary

Gets an InlineCollection containing the top-level inline elements that include the contents of Span.

Constructors

  • Span()
    Span()
    Span()
    Span()

    Initializes a new instance of the Span class.

    public Span()public Span()Public Function Span() As

Properties

  • Inlines
    Inlines
    Inlines
    Inlines

    Gets an InlineCollection containing the top-level inline elements that include the contents of Span.

    public InlineCollection Inlines { get; set; }public InlineCollection Inlines { get; set; }Public ReadWrite Property Inlines As InlineCollection
    <Span ...>
      oneOrMoreInlines
    </Span>
    -or-
    <Span ...>
      mixedContent
    </Span>
    

    Property Value

    Remarks

    Hyperlink has restrictions on the content that can exist in its Inlines colllection. Specifically, a Hyperlink only permits Run and other Span types that aren't another Hyperlink. InlineUIContainer can't be in the Inlines colllection of a Hyperlink. Attempting to add restricted content throws an invalid args exception or XAML parse exception.

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.WebHostHiddenAttribute
Windows.Foundation.Metadata.ComposableAttribute
Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.UI.Xaml.Markup.ContentPropertyAttribute
Windows.Foundation.Metadata.ThreadingAttribute

Details

Assembly

Windows.UI.Xaml.Documents.dll