TextFormatter.FormatMinMaxParagraphWidth Method (TextSource, Int32, TextParagraphProperties)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Returns a value that represents the smallest and largest possible paragraph width that can fully contain the specified text content.

Namespace:   System.Windows.Media.TextFormatting
Assembly:  PresentationCore (in PresentationCore.dll)

public abstract MinMaxParagraphWidth FormatMinMaxParagraphWidth(
	TextSource textSource,
	int firstCharIndex,
	TextParagraphProperties paragraphProperties


Type: System.Windows.Media.TextFormatting.TextSource

A TextSource object that represents the text source for the line.

Type: System.Int32

An Int32 value that specifies the character index of the starting character in the line.

Type: System.Windows.Media.TextFormatting.TextParagraphProperties

A TextParagraphProperties object that represents paragraph properties, such as flow direction, alignment, or indentation.

Return Value

Type: System.Windows.Media.TextFormatting.MinMaxParagraphWidth

A MinMaxParagraphWidth value that represents the smallest and largest possible paragraph width that can fully contain the specified text content.

The following text uses the minimum paragraph width for the source text, which displays as multiple lines. The minimum paragraph width corresponds to the word that has the greatest width—in this case, the word "jumped". Notice that multiple words can appear on the same line, as long as the total width does not exceed the minimum paragraph width.

Text Formatter using the minimum paragraph width

Minimum paragraph width

The following example shows how to use the FormatMinMaxParagraphWidth method to generate the minimum paragraph width for the formatted lines of text.

MinMaxParagraphWidth minMaxParaWidth =
    formatter.FormatMinMaxParagraphWidth(customTextSource, 0, customTextParagraphProperties);

// Format each line of text from the text store and draw it.
while (textStorePosition < customTextSource.Text.Length)
    // Create a textline from the text store using the TextFormatter object.
    using (TextLine myTextLine = formatter.FormatLine(
        // Draw the formatted text into the drawing context.
        myTextLine.Draw(drawingContext, linePosition, InvertAxes.None);

        // Update the index position in the text store.
        textStorePosition += myTextLine.Length;

        // Update the line position coordinate for the displayed line.
        linePosition.Y += myTextLine.Height;

.NET Framework
Available since 3.0
Return to top