【发布时间】:2011-01-05 01:05:41
【问题描述】:
我有问题,这让我很生气。下面是一个简单的例子
<Grid Name="_grid">
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="36,33,0,0" Name="button" VerticalAlignment="Top" Width="75" />
<Button Content="Enlarge through animation" Height="23" Margin="172,33,24,0" Name="_animateButton" VerticalAlignment="Top" Click="_animateButton_Click" />
<Button Content="Enlarge through simple heigh changing" Height="23" Margin="172,62,24,0" Name="_resizeButton" VerticalAlignment="Top" Click="_resizeButton_Click" />
</Grid>
在后面的代码中
private void _resizeButton_Click(object sender, RoutedEventArgs e)
{
button.Height += 10;
}
private void _animateButton_Click(object sender, RoutedEventArgs e)
{
Storyboard storyboard = new Storyboard();
DoubleAnimation animation = new DoubleAnimation(button.Height + 10, new Duration(new TimeSpan(0, 0, 0, 1)));
storyboard.Children.Add(animation);
Storyboard.SetTargetName(animation, button.Name);
Storyboard.SetTargetProperty(animation, new PropertyPath(HeightProperty));
storyboard.Begin(_grid);
}
应用程序看起来像这样
按下_resizeButton左键后立即放大。然后我按下 _animateButton - 左按钮正在缓慢放大。在此之后,我再次按下 _resizeButton 并没有发生任何事情。这是为什么呢?
我注意到在设置 Top 属性动画时也是如此
【问题讨论】:
标签: c# wpf animation dependency-properties