在多个视图框中设置相同的字体大小 [英] Setting the same font size across multiple viewboxes

查看:145
本文介绍了在多个视图框中设置相同的字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我有两个带有两个文本块的视图框.它们的宽度和高度都相同,但是文本的长度不会相同.不管字符数如何,如何使它们具有相同的字体大小?

Let's say I have two viewboxes with two textblocks inside them. They both have the same Width and Height, but the text won't be the same length. How could I make them have the same font size, regardless of the number of characters?

代码示例:

<Viewbox x:Name="vb1">
    <TextBlock Text="Some text" />
</Viewbox>
<Viewbox x:Name="vb2">
    <TextBlock Text="Some bigger text" />
</Viewbox>

这就是我想要的:

推荐答案

将两个TextBlock控件放在同一ViewBox中:

Place both TextBlock controls in the same ViewBox:

<Viewbox>
    <Grid>
        <TextBlock Text="Some text" />
        <TextBlock Text="Some bigger text" />
    </Grid>
</Viewbox>

迈克·斯特罗贝尔(Mike Strobel)说的很有意义我不确定您是否要重叠文本.如果不是,则将Grid替换为StackPanel,以获得如下效果:

What Mike Strobel said makes sense; I'm not sure if you want to overlap the text or not. If not, then replace the Grid with a StackPanel to get an effect like this:

要使其并排放置,可以使用Grid并设置列宽... YMMV.我不确定还有什么建议,因为我不确定您要达到的目标.

To place them side-by-side, you could play around with a Grid and setting column widths... YMMV. I'm not sure what else to suggest because I'm not exactly sure what you're trying to achieve.

<Viewbox>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300" />
            <ColumnDefinition Width="300" />
        </Grid.ColumnDefinitions>
        <TextBlock Text="Some text" />
        <TextBlock Text="Some bigger text" Grid.Column="1" />
    </Grid>
</Viewbox>

这篇关于在多个视图框中设置相同的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆