共用方式為


Run

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Represents a discrete section of formatted or unformatted text.

<Run .../>

Managed Equivalent

Run

Remarks

Run is one of the few Silverlight objects that supports inner text as a XAML element. The inner text is parsed and becomes the value of the Text property in the Silverlight object model.

The inner text of a TextBlock object in XAML is also processed as a Run object with a Text value.

You can declare multiple Run objects in an Inlines collection. By applying specific property formatting to various Run objects, and introducing LineBreak objects, you can introduce basic text formatting to text blocks.

Example

The following example shows how to define several differently formatted text strings in a TextBlock object by using Run objects.

<!-- Display formatted text as Run objects in a TextBlock. -->
<Canvas
  xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation">

<TextBlock
  FontFamily="Arial" Width="400" Text="Sample text formatting runs">
  <LineBreak/>
  <Run Foreground="Maroon" FontFamily="Courier New" FontSize="24">Courier New 24</Run>
  <LineBreak/>
  <Run Foreground="Teal" FontFamily="Times New Roman" FontSize="18" FontStyle="Italic">Times New Roman Italic 18</Run>
  <LineBreak/>
  <Run Foreground="SteelBlue" FontFamily="Verdana" FontSize="14" FontWeight="Bold">Verdana Bold 14</Run>
</TextBlock>

</Canvas>

The following illustration shows the rendered formatted text from the previous XAML content example.

Rendered formatted text

Sample of text formatting runs.

Notice that the LineBreak object forces the text in each Run to display on a separate line. Without the LineBreak object, the text in each Run would flow together as one line and eventually be truncated after exceeding the Width property value of the TextBlock. The following illustration shows how the formatted text would render without using LineBreak objects.

Rendered formatted text without line breaks

Sample text formatting runs.

See Also

Reference