You can wrap your TextBlock
with a Viewbox, like the following:
<Button>
<Viewbox>
<TextBlock Text="Text Text" />
</Viewbox>
</Button>
Edited:
For setting the same fontsize to the whole of the TextBlock
s, you can scale the fontsize of the whole of the TextBlock
s, according to the TextBlock
with the minimal scale.
To achieve the scale effect, the Viewbox
wraps the element with a ContainerVisual
and, performs a scale on it. You can add an event-handler to the SizeChanged
event of the Viewbox
. In this event-handler you can use the scale value of the ContainerVisual
that wraps the TextBlock
to change the fontsize of the other TextBlock
s, like the following example:
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Button>
<Viewbox Name="vb1" StretchDirection="DownOnly" SizeChanged="vb1_SizeChanged">
<TextBlock Name="tb1" Text="Text Text" FontSize="72" />
</Viewbox>
</Button>
<Button Grid.Row="1">
<Viewbox Name="vb2" StretchDirection="DownOnly">
<TextBlock Name="tb2" Text="Text2" FontSize="72" />
</Viewbox>
</Button>
</Grid>
private void vb1_SizeChanged(object sender, SizeChangedEventArgs e)
{
ContainerVisual cv = VisualTreeHelper.GetParent(tb1) as ContainerVisual;
ScaleTransform st = cv != null ? cv.Transform as ScaleTransform : null;
if (st != null)
{
tb2.FontSize = 72 * st.ScaleX;
}
}
In this example we have a Grid
that has only 2 buttons and, the 1st TextBlock
effects the 2nd. But, you can use the idea also for more complicated cases.