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