Setting the same font size across multiple viewboxes

自作多情 提交于 2019-12-14 02:43:48

问题


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?

Code example:

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

Here's what I would like:


回答1:


Place both TextBlock controls in the same ViewBox:

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

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:

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>


来源:https://stackoverflow.com/questions/26609703/setting-the-same-font-size-across-multiple-viewboxes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!