What is the easiest to animate the position of but

2019-03-03 20:37发布

I want to move a button across a canvas when it's clicked in a way that it changes its position gradually(animation), not vanishing and reappearing in the new position.

1条回答
forever°为你锁心
2楼-- · 2019-03-03 21:10

You can use a Storyboard that will move it smoothly:

    <Grid>
    <Canvas>
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="50,250,0,0" Name="buttonAnimate" VerticalAlignment="Top" Width="75">
            <Button.Triggers>
                <EventTrigger RoutedEvent="Button.Click">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation From="0" To="100" Duration="0:0:2" Storyboard.TargetProperty="(Canvas.Left)" AutoReverse="False" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Button.Triggers>    
        </Button>
    </Canvas>
</Grid>
查看更多
登录 后发表回答