因为在Silverlight中没有ThicknessAnimation,所以为Margin添加动画有点麻烦:
1. 使用ObjectAnimationUsingKeyFrames来做,这个就是通过计算要显示的每一帧内容来设置动画,可能看起来不是那么平滑,如果需要平滑的话,那样就需要写代码来动态生成动画效果,看起来会平滑很多。
使用XAML来进行描述就是这样:
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="150"/>
</Grid.RowDefinitions>
<Grid.Resources>
<Storyboard x:Name="sb">
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Margin"
Storyboard.TargetName="bdTest">
<DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
<DiscreteObjectKeyFrame KeyTime="0:0:0.5">
<DiscreteObjectKeyFrame.Value>
<Thickness>3,7,5,9</Thickness>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:0.6">
<DiscreteObjectKeyFrame.Value>
<Thickness>4,8,6,10</Thickness>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:0.7">