DoubleAnimation.IsAdditive 属性:MSDN
<Grid Height="181" Name="grid1" Width="332">
    <Button Content="Button" Height="23" HorizontalAlignment="Center" Name="button1" VerticalAlignment="Center" Width="75" Click="button1_Click" />
    </Grid>
DoubleAnimation widthAnimation = new DoubleAnimation();
widthAnimation.From = 20;
widthAnimation.To = 100;
widthAnimation.Duration = TimeSpan.FromSeconds(0.5);
button1.BeginAnimation(Button.WidthProperty, widthAnimation);
widthAnimation.IsAdditive = true;
2个问题:
1:
把IsAdditive属性设置为了true,为什么单击按钮的时候,Width突然缩小了,然后才允许动画?起始值应该是当前值加上20的啊?2:多次单击按钮,为什么按钮不是越来越大,加上当前值,应该是越来越大的吧

解决方案 »

  1.   

    widthAnimation.From = 20;
    widthAnimation.To = 100;就是从20开始100结束.....
      

  2.   

    未见楼主说的异常情况,我这里一切正常
    DoubleAnimation widthAnimation = new DoubleAnimation();         public MainWindow()
            {
                InitializeComponent();
                
                widthAnimation.From = 20; 
                widthAnimation.To = 100; 
                widthAnimation.Duration = TimeSpan.FromSeconds(0.5);             
                widthAnimation.IsAdditive = true;
            }        private void button1_Click(object sender, RoutedEventArgs e)
            {
                button1.BeginAnimation(Button.WidthProperty, widthAnimation); 
            }<Grid>
            <Button Content="Button" Height="23" HorizontalAlignment="Center" Name="button1" VerticalAlignment="Center" Width="75" Click="button1_Click" />
        </Grid>
      

  3.   

    我猜楼主的第二部分代码写在了Button的Click事件中,造成每次点击都是重新开始动画,而且设置DoubleAnimation.IsAdditive属性应该是放在实例化DoubleAnimation后立即设置的吧,所以,楼主想达到预想的效果,应该吧代码改成3楼那样。
      

  4.   

    噢,刚才在4楼说错了,测试过,即使代码放在Button的Click事件中也可以,重点是实例化DoubleAnimation后,应该立即设置IsAdditive属性,不应该放最后。