大家,我尝试缩放按钮的大小,代码工作正常,如果我只单击一次,但如果我连续单击多次按钮,按钮无法返回其原始大小。这是代码:
private void ButtonSearchMedication_OnClick(object sender, RoutedEventArgs e)
{
//Assign variation of width in term of begin, end and duration
DoubleAnimation widthAnimation =new DoubleAnimation(ButtonSearchMedication.ActualWidth, ButtonSearchMedication.ActualWidth*0.8, new Duration(timeSpan:TimeSpan.FromSeconds(0.2)) );
//Assign variation of height in term of begin, end and duration
DoubleAnimation heightAnimation = new DoubleAnimation(ButtonSearchMedication.ActualHeight,ButtonSearchMedication.ActualHeight*0.8, new Duration(timeSpan:TimeSpan.FromSeconds(0.2)));
//Assign properties to button
ButtonSearchMedication.BeginAnimation(Button.WidthProperty,widthAnimation);
ButtonSearchMedication.BeginAnimation(Button.HeightProperty,heightAnimation);
}
私人无效ButtonSearchMedication_OnMouseLeave(对象发送者,MouseEventArgs e){
DoubleAnimation widthAnimation = new DoubleAnimation(ButtonSearchMedication.ActualWidth, ButtonSearchMedication.ActualWidth*1.25,new Duration(timeSpan:TimeSpan.FromSeconds(0.2)));
DoubleAnimation heightAnimation = new DoubleAnimation(ButtonSearchMedication.ActualHeight, ButtonSearchMedication.ActualHeight*1.25,new Duration(timeSpan:TimeSpan.FromSeconds(0.2)));
ButtonSearchMedication.BeginAnimation(Button.WidthProperty,widthAnimation);
ButtonSearchMedication.BeginAnimation(Button.HeightProperty,heightAnimation);
}
我能做些什么来确保按钮的大小在每次 MouseLeave 后变为原来的大小吗?谢谢