Search code examples
xamlanimationuwpuwp-xamlwindows-community-toolkit

How animate margin in UWP?


I'm try use

    <animations:AnimationCollection x:Name="UnHoverCollection">
      <animations:Vector2Animation To="10,10" Target="Margin" />
    </animations:AnimationCollection>

and this animations

    <animations:AnimationCollection x:Name="UnHoverCollection">
      <animations:Vector4Animation To="10,10,10,10" Target="Margin" />
    </animations:AnimationCollection>

and take next error

"The specified property was not found or cannot be animated. Context: Margin Expression: Margin Start Position: 0, End Position: 6"

How do this animation?


Solution

  • If you want to move the object, animating the margin is not a good idea. These animation types are mainly operated according to X, Y coordinate. I suggest that you can use TranslationAnimation or OffsetAnimations. You can refer to this document to move the object.