asitis
asitis

Reputation: 3031

How do i adjust font size of a textblock with respect to the Text Length in Windows 8 xaml

I am using a Textblock in a Listbox Template . Where i wants to vary the Textblock Size with respect to the Content Text.

Small Text --> Large FontSize && Large Text --> Small font Size

So that it filled in the template.
How do we achieve this since Letters are taking varied occupied spaces.
Example: 'i' takes less space than 'w' / Capital letters took more spaces than Small letters.

    <StackPanel HorizontalAlignment="Left" Height="30" VerticalAlignment="Top" Width="74" Margin="355,101,0,0" Background="#FF139905">
        <TextBlock TextWrapping="Wrap" Text="This is a test application" Foreground="Black" FontWeight="Bold" FontSize="12"/>
    </StackPanel>
    <StackPanel HorizontalAlignment="Left" Height="30" VerticalAlignment="Top" Width="74" Margin="355,155,0,0" Background="#FF0FAA00">
        <TextBlock TextWrapping="Wrap" Text="This is a test " Foreground="Black" FontWeight="Bold" FontSize="13.333"/>
    </StackPanel>
    <StackPanel HorizontalAlignment="Left" Height="30" VerticalAlignment="Top" Width="74" Margin="355,204,0,0" Background="#FF0FAA00">
        <TextBlock TextWrapping="Wrap" Text="test " Foreground="Black" FontWeight="Bold" FontSize="26.667"/>
    </StackPanel>

enter image description here

Upvotes: 1

Views: 1972

Answers (1)

Fede
Fede

Reputation: 44028

Converting my comment into an answer:

Put the textblock in a Viewbox.

<Viewbox>
   <TextBlock/>
</Viewbox>

Upvotes: 4

Related Questions