【问题标题】:WPF textblock animationWPF 文本块动画
【发布时间】:2016-07-21 07:35:44
【问题描述】:

如何实现THIS类型的动画?我对 WPF 很陌生。 我尝试在 WPF 中使用DoubleAnimation,但没有达到目标。

当我更新分数时应该会发生动画,就像视频中分数从 17 更新到 23 时一样。

【问题讨论】:

  • 我看不到您发布的链接:此网站负载过重 :-) 我稍后再试!
  • 我看到了动画。在这里为您编写 XAML 很困难。基本上你需要两个 DoubleAnimation:一个控制 TextBlock 的不透明度,另一个控制翻译。
  • 谢谢!伊戈尔·达米亚尼。但老实说,我不知道如何写这个:) 我还是会尝试。如果您能提供更多帮助,请帮助我。仅供参考,我正在使用 VS 2015

标签: wpf textblock wpf-animation


【解决方案1】:

试试这个。

<Window x:Class="WpfApplication1.AnimWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WpfApplication1"
    mc:Ignorable="d"
    Title="AnimWindow" Height="300" Width="300">

<Window.Triggers>
    <EventTrigger RoutedEvent="Window.Loaded">
        <BeginStoryboard>
            <Storyboard>
                <DoubleAnimation Storyboard.TargetName="PointsNew" To="1.0" Storyboard.TargetProperty="Opacity" Duration="0:0:0.5" />
                <DoubleAnimation Storyboard.TargetName="PointsOld" To="0.0" Storyboard.TargetProperty="Opacity" Duration="0:0:0.5" />
                <ThicknessAnimation Storyboard.TargetName="PointsNew" From="0 -32 0 0" To="0 0 0 0" Storyboard.TargetProperty="Margin" Duration="0:0:0.5" />
                <ThicknessAnimation Storyboard.TargetName="PointsOld" To="0 32 0 0" Storyboard.TargetProperty="Margin" Duration="0:0:0.5" />
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
</Window.Triggers>

<Grid>
    <Border HorizontalAlignment="Center" VerticalAlignment="Center" Opacity="0.0" x:Name="PointsNew">
        <TextBlock Text="23" FontSize="96" FontWeight="Bold" />
    </Border>
    <Border HorizontalAlignment="Center" VerticalAlignment="Center" Opacity="1.0" x:Name="PointsOld">
        <TextBlock Text="17" FontSize="96" FontWeight="Bold" />
    </Border>
</Grid></Window>

尝试使用边距、持续时间等! :-)

【讨论】:

  • 谢谢。让我试试。
  • 天哪,你太棒了!这正是我想要的。非常感谢。谢谢,谢谢,谢谢(y)
猜你喜欢
  • 2015-01-11
  • 1970-01-01
  • 2013-02-25
  • 2011-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多