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:多次单击按钮,为什么按钮不是越来越大,加上当前值,应该是越来越大的吧
<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:多次单击按钮,为什么按钮不是越来越大,加上当前值,应该是越来越大的吧
widthAnimation.To = 100;就是从20开始100结束.....
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>