如何在XAML中加载动画?

5uzkadbs  于 11个月前  发布在  其他
关注(0)|答案(2)|浏览(103)

我希望我的文本块从左边出现,并转换到它的位置,但它不工作。
我试了这个代码,但是文本不能从左边转换。我做错了什么?我不能使用WPF或C#,只能使用XAML。

<TextBlock Foreground="#365B6D"  Margin="0, 20, 0, 0" Style="{StaticResource topsmalltext}" TextAlignment="Center">Who uses social media?
          <TextBlock.Triggers>
                    <EventTrigger RoutedEvent="TextBlock.Loaded">
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation From="-384" To="0" Storyboard.TargetProperty="(RenderTransform).(TranslateTransform.X)" Duration="0:0:2">
                                </DoubleAnimation>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
          </TextBlock>

字符串

qnakjoqk

qnakjoqk1#

试试这个:

<TextBlock Foreground="#365B6D" Margin="0,20,0,0" Style="{StaticResource topsmalltext}" TextAlignment="Center">
Who uses social media?
<TextBlock.Triggers>
    <EventTrigger RoutedEvent="TextBlock.Loaded">
        <BeginStoryboard>
            <Storyboard>
                <DoubleAnimation From="-384" To="0" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="0:0:2" />
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
</TextBlock.Triggers>

字符串
在您示例中,您忘记包含此</TextBlock.Triggers>

umuewwlo

umuewwlo2#

我以这种方式解决了这个问题:

<TextBlock x:Name="textBlock1" Foreground="#365B6D"  Margin="0, 20, 0, 0" Style="{StaticResource topsmalltext}" TextAlignment="Center">Who uses socia media?
      <TextBlock.RenderTransform>
        <TranslateTransform X="-450" />
    </TextBlock.RenderTransform>
    <TextBlock.Triggers>
        <EventTrigger RoutedEvent="TextBlock.Loaded">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation
                        Storyboard.TargetName="textBlock1"
                        Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)"
                        From="450" To="0" Duration="0:0:2" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </TextBlock.Triggers>
</TextBlock>

字符串

相关问题