方法一、
C#代码完成
private void Button_Click_1(object sender, RoutedEventArgs e)
{
//timer = new DispatcherTimer();
//timer.Interval = TimeSpan.FromMilliseconds(100);
//timer.Tick += timer_Tick;
//timer.Start();
Storyboard sb = new Storyboard();
DoubleAnimation da = new DoubleAnimation();
da.From = 100;
da.To = 500;
da.Duration = new Duration(TimeSpan.FromMilliseconds(2000));
Storyboard.SetTarget(da, btn);
Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.Height)"));
sb.Children.Add(da);
sb.Begin();
//sb.Begin();
}
触发该事件,改变控件btn的Height,2S内高度100到500
方法二、
xaml内实现
<phone:PhoneApplicationPage.Resources>
<Storyboard x:Name="sb">
<DoubleAnimation Storyboard.TargetName="rectangle" Storyboard.TargetProperty="Height"
From="100" To="500" Duration="0:0:5">
</DoubleAnimation>
</Storyboard>
</phone:PhoneApplicationPage.Resources>
启动sb.begin()方法使矩形高度5S内从100到500
注意:使用属性的改变实现动画效果效率低.