How to load an animation in XAML?

45 views Asked by At

I want my text block to appear from the left and tranform to its position, but it doesn't work.

I tried this code, but the text isn't transforming from the left. What did I do wrong? I am not allowed use WPF or C#, only 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>
2

There are 2 answers

1
Yoji On

try this:

<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>

in your example you forgot to include this </TextBlock.Triggers>

0
arctg30 On

I fixed this problem in such way:

<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>