LineStackingStrategy in Silverlight 3

17 Oct

LineStackingStrategy is one of the properties you can set on a TextBlock in Silverlight that enables you to get better control over how text is displayed.

LineStackingStrategy has two valid values: BlockLineHeight and MaxHeight. BlockLineHeight uses the LineHeight defined at the TextBlock even if the elements in the TextBlock actually requires more space. MaxHeight will compensate for this and will use the smallest lineheight required by all elements in the TextBlock.

Lets take a look at an example:

<TextBlock
    TextWrapping="Wrap"
    LineHeight="12"
    LineStackingStrategy="MaxHeight">
        <Run
        FontSize="12">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
        incididunt ut labore et dolore magna aliqua.</Run>
        <Run
        FontSize="28"
        Foreground="Red">Ut enim ad minim veniam, quis nostrud exercitation
        ullamco laboris nisi ut aliquip ex ea commodo consequat.</Run>
        <Run
        FontSize="12">Duis aute irure dolor in reprehenderit
        in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
        non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</Run>
</TextBlock>

If we use BlockLineHeight:

2009-10-17_141153

If we use Maxheight:

2009-10-17_141225

by xamlgeek

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: