使用Viewbox缩放文字 [英] Scaling text with Viewbox

查看:122
本文介绍了使用Viewbox缩放文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的UI要求要求多个TextBlock在一个Window中缩放.没问题,将它们包装在Viewbox中-效果很好.

这是我的问题;要求指出 all TextBlocks中的字体大小必须相同.对我来说,最大的字体需要缩小为最小的字体.

以下XAML文件说明了我的问题.如果将Window的大小调整为窄高,则"Hello World"的尺寸将比"Hello"的尺寸短得多.

关于如何实现这一目标的任何想法?

我有一个List<>在所有Viewbox中,最大为8.我可以在所有ViewBox的SizeChanged事件上设置MaxHeight,但是我被卡在那里.

任何帮助将不胜感激.

预先感谢,

杰森


Hi All,

My UI requirement calls for multiple TextBlocks to scale within a Window. Not a problem, wrap them in a Viewbox - works great.

Here''s my problem; The requirement states the font size must be the same in all TextBlocks. What that means to me is the largest font needs to scale down to the smallest font.

The following XAML file illustrates my issue. "Hello World" will be a much shorter size than "Hello" if I resize the Window to be narrow and tall.

Any ideas on how to achieve this?

I have a List<> of all Viewboxes, max is 8. I can set MaxHeight on a SizeChanged event on all of them, but I get stuck there.

Any help would be greatly appreciated.

Thanks in advance,

Jason


<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="400" Width="300">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Viewbox x:Name="V1" Grid.Column="0" Grid.Row="0">
            <TextBlock x:Name="T1">Hello World</TextBlock>
        </Viewbox>
        <Viewbox x:Name="V2" Grid.Column="0" Grid.Row="1">
            <TextBlock x:Name="L2">Hello</TextBlock>
        </Viewbox>
    </Grid>
</Window>

推荐答案

嗨杰森,

您不需要事件,也不需要其他大小调整属性;只需将Grid放在Viewbox中,并插入所有具有相同FontSize的TextBlocks.这样,您还可以使用多行文本.

对于您的示例,如果需要,您可能必须向TextBlocks添加一些对齐方式属性,以类似于ViewBox的标准行为.

欢呼声
于尔根(Jürgen)
Hi Jason,

you don''t need events nor additional sizing properties; just put only the Grid in a Viewbox and insert all TextBlocks with the same FontSize. This way you can also use multiline texts.

For your example, you might have to add some alignment properties to the TextBlocks, to resemble the ViewBox''s standard behaviour, if that is needed.

Cheers
Jürgen


这篇关于使用Viewbox缩放文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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