wpf 动画结束后保留end值,动画结束后会失去绑定,可以在completed事件重新进行绑定
https://blog.csdn.net/openzpc/article/details/50588063
动画结束后会失去绑定,可以在completed事件重新进行绑定
rightToLeftInverseAnimation = new ThicknessAnimation();
rightToLeftInverseAnimation.From = new Thickness(btnIcon.Margin.Left - menuPanelOriWidth + btnIcon.Width, btnIcon.Margin.Top, btnIcon.Margin.Right, btnIcon.Margin.Bottom);
rightToLeftInverseAnimation.To = new Thickness(btnIcon.Margin.Left, btnIcon.Margin.Top + btnIcon.Width, btnIcon.Margin.Right, btnIcon.Margin.Bottom);
rightToLeftInverseAnimation.Duration = TimeSpan.FromMilliseconds(animationTimesMs);
rightToLeftInverseAnimation.FillBehavior = FillBehavior.Stop;
rightToLeftInverseAnimation.Completed += new EventHandler((sender, e) =>
{
menu.Margin = btnIcon.Margin;
Binding binding = new Binding();
binding.Path = new System.Windows.PropertyPath(MarginProperty);
binding.Mode = BindingMode.OneWay;
binding.ElementName = "btnIcon";
binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
menu.SetBinding(MarginProperty, binding);
});
Storyboard.SetTargetName(rightToLeftInverseAnimation, nameof(menu));
Storyboard.SetTargetProperty(rightToLeftInverseAnimation, new PropertyPath(Panel.MarginProperty));
if (!hideStoryboard.Children.Contains(rightToLeftInverseAnimation))
{
hideStoryboard.Children.Add(rightToLeftInverseAnimation);
}