I have a panel with several TextBlock
s. I want to modify this panel such that the font size of each TextBlock changes depending on the size of the panel.
The size of the panel can change when the user changes the size of the window (e. g. maximizes or restores it).
I tried to do it using a Viewbox
:
<Viewbox Stretch="Fill">
<Grid Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Viewbox}}, Path=Width}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
<TextBlock
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
<TextBlock
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
<TextBlock
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
<TextBlock
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
<TextBlock
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
</Grid>
</Viewbox>
But it doesn't work because
- font size doesn't get bigger, when the size of the
Viewbox
increases and - it doesn't get smaller, when the size of the
Viewbox
decreases.
How can implement scaling of these text blocks (so that they fill the entire available area, and adapt their font sizes) ?
You have height width auto and you are not placing the textblocks in the grid