如何在WPF中为标签添加字体加粗的动画效果?

8

我在寻找一种动画故事板类型,可以让我将标签的FontWeight属性从“Normal”变为“Bold”进行动画化。有没有人有相关经验?

2个回答

18

假设你的标签的初始字重是Normal,就像下面这样:

<Label x:Name="label" Content="Label" HorizontalAlignment="Left" FontWeight="Normal" VerticalAlignment="Top"/>

以下是可以用于将标签的字体加粗的Storyboard:

<Storyboard>
     <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.FontWeight)" Storyboard.TargetName="label">
        <DiscreteObjectKeyFrame KeyTime="0">
            <DiscreteObjectKeyFrame.Value>
                <FontWeight>Bold</FontWeight>
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
    </ObjectAnimationUsingKeyFrames>
</Storyboard>

0
你可以使用一个将double类型转换为FontWeight类型的转换器(当动画值超过一定阈值时切换为粗体),但我认为你不能在这两种状态之间实现非常平滑的动画效果。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接