Share via

Why does Implicit.HideAnimations shift an Element on the X axis?

Hong 1,526 Reputation points
2021-02-05T16:46:55.83+00:00

The following code works great for showing the Grid

<Grid
    Width="300"
    Visibility="{x:Bind bShow, Converter={StaticResource BooleanToVisibilityConverter}}"
    Background="#8111"
    Padding="5">
    <animations:Implicit.ShowAnimations>
        <animations:TranslationAnimation Duration="0:0:1" From="0, 200, 0" To="0" ></animations:TranslationAnimation>
        <animations:OpacityAnimation Duration="0:0:3" From="0" To="1.0"></animations:OpacityAnimation>
    </animations:Implicit.ShowAnimations>
    <animations:Implicit.HideAnimations>
        <animations:ScalarAnimation Target="Translation.Y" Duration="0:0:1" From="-200"  To="0"/>
    </animations:Implicit.HideAnimations>

However, it shifts the Grid to the right when hiding the Grid. I have to add the following to get around it:

<animations:ScalarAnimation Target="Translation.X" Duration="0:0:1" From="-150"  To="-150"/>

Could anyone shed some light on this?

Developer technologies | Universal Windows Platform (UWP)

1 answer

Sort by: Most helpful
  1. Anonymous
    2021-02-11T06:10:19.63+00:00

    Hello,

    Welcome to Microsoft Q&A!

    However, it shifts the Grid to the right when hiding the Grid.

    According to the result I got after testing, the behavior you got is caused by the HorizontalAlignment property of the UserControl object. If I move it, the Grid will not move on the X-axis when the bShow changes to false. I've confirmed it with the sample you provided. It looks like the UserControl's position is recalculated when it is going to begin the hidden animation due to the HorizontalAlignment property.

    Like this:

       <local:MyUserControl1  
                x:Name="ucDebug"  
                    VerticalAlignment="Bottom"/>  
    

    Thank you.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.