Επεξεργασία

Κοινή χρήση μέσω


TextFormatter.FormatMinMaxParagraphWidth Method

Definition

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

Overloads

FormatMinMaxParagraphWidth(TextSource, Int32, TextParagraphProperties)

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

FormatMinMaxParagraphWidth(TextSource, Int32, TextParagraphProperties, TextRunCache)

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

FormatMinMaxParagraphWidth(TextSource, Int32, TextParagraphProperties)

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

public:
 abstract System::Windows::Media::TextFormatting::MinMaxParagraphWidth FormatMinMaxParagraphWidth(System::Windows::Media::TextFormatting::TextSource ^ textSource, int firstCharIndex, System::Windows::Media::TextFormatting::TextParagraphProperties ^ paragraphProperties);
public abstract System.Windows.Media.TextFormatting.MinMaxParagraphWidth FormatMinMaxParagraphWidth (System.Windows.Media.TextFormatting.TextSource textSource, int firstCharIndex, System.Windows.Media.TextFormatting.TextParagraphProperties paragraphProperties);
abstract member FormatMinMaxParagraphWidth : System.Windows.Media.TextFormatting.TextSource * int * System.Windows.Media.TextFormatting.TextParagraphProperties -> System.Windows.Media.TextFormatting.MinMaxParagraphWidth
Public MustOverride Function FormatMinMaxParagraphWidth (textSource As TextSource, firstCharIndex As Integer, paragraphProperties As TextParagraphProperties) As MinMaxParagraphWidth

Parameters

textSource
TextSource

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

firstCharIndex
Int32

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

paragraphProperties
TextParagraphProperties

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

Returns

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

Examples

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(
        customTextSource,
        textStorePosition,
        minMaxParaWidth.MinWidth,
        customTextParagraphProperties,
        null))
    {
        // 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;
    }
}
Dim minMaxParaWidth As MinMaxParagraphWidth = formatter.FormatMinMaxParagraphWidth(customTextSource, 0, customTextParagraphProperties)

' Format each line of text from the text store and draw it.
Do While textStorePosition < customTextSource.Text.Length
    ' Create a textline from the text store using the TextFormatter object.
    Using myTextLine As TextLine = formatter.FormatLine(customTextSource, textStorePosition, minMaxParaWidth.MinWidth, customTextParagraphProperties, Nothing)
        ' 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
    End Using
Loop

Remarks

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

Applies to

FormatMinMaxParagraphWidth(TextSource, Int32, TextParagraphProperties, TextRunCache)

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

public:
 abstract System::Windows::Media::TextFormatting::MinMaxParagraphWidth FormatMinMaxParagraphWidth(System::Windows::Media::TextFormatting::TextSource ^ textSource, int firstCharIndex, System::Windows::Media::TextFormatting::TextParagraphProperties ^ paragraphProperties, System::Windows::Media::TextFormatting::TextRunCache ^ textRunCache);
public abstract System.Windows.Media.TextFormatting.MinMaxParagraphWidth FormatMinMaxParagraphWidth (System.Windows.Media.TextFormatting.TextSource textSource, int firstCharIndex, System.Windows.Media.TextFormatting.TextParagraphProperties paragraphProperties, System.Windows.Media.TextFormatting.TextRunCache textRunCache);
abstract member FormatMinMaxParagraphWidth : System.Windows.Media.TextFormatting.TextSource * int * System.Windows.Media.TextFormatting.TextParagraphProperties * System.Windows.Media.TextFormatting.TextRunCache -> System.Windows.Media.TextFormatting.MinMaxParagraphWidth
Public MustOverride Function FormatMinMaxParagraphWidth (textSource As TextSource, firstCharIndex As Integer, paragraphProperties As TextParagraphProperties, textRunCache As TextRunCache) As MinMaxParagraphWidth

Parameters

textSource
TextSource

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

firstCharIndex
Int32

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

paragraphProperties
TextParagraphProperties

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

textRunCache
TextRunCache

A TextRunCache object that represents the caching mechanism for the layout of text.

Returns

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

Applies to