Skip to content

Latest commit

 

History

History
61 lines (46 loc) · 3.38 KB

File metadata and controls

61 lines (46 loc) · 3.38 KB
-api-id -api-type
T:Microsoft.UI.Xaml.Documents.Span
winrt class

Microsoft.UI.Xaml.Documents.Span

-description

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

-xaml-syntax

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

-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 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:

-examples

-see-also

Inline, Paragraph