我有以下动画,它就像一个魅力:
<Window.Resources>
<Namespace:MathConverter Core:Key="MathConverter"/>
<Storyboard Core:Key="MyKey" Completed="OnCompleted">
<DoubleAnimation Storyboard.TargetProperty="(Canvas.Left)" BeginTime="00:00:00.0" By="135" Duration="00:00:0.2"/>
<DoubleAnimation Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(TransformGroup.Children)[1].(ScaleTransform.ScaleX)" BeginTime="00:00:00.2" Duration="00:00:00.1" To="0">
<DoubleAnimation.EasingFunction>
<QuinticEase EasingMode="EaseInOut"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
</Window.Resources>
现在......我的布局是根据一些特定的基本值动态构建的。我希望我的动画以同样的方式表现。问题是,如果我按如下方式修改我的声明(MultiBinding Converter 的返回值绝对正确,我仔细检查了它)它就会停止正常工作:
<Storyboard Core:Key="MyKey" Completed="OnCompleted">
<DoubleAnimation Storyboard.TargetProperty="(Canvas.Left)" BeginTime="00:00:00.0" Duration="00:00:0.2">
<DoubleAnimation.By>
<MultiBinding Converter="{StaticResource MathConverter}" ConverterParameter="((x - y) / 2) + z + w">
<Binding Source="{Core:Static Namespace:MyClass.RealHeight}"/>
<Binding Source="{Core:Static Namespace:MyClass.RealWidth}"/>
<Binding Source="{Core:Static Namespace:MyClass.MarginInner}"/>
<Binding Source="{Core:Static Namespace:MyClass.RealWidth}"/>
</MultiBinding>
</DoubleAnimation.By>
</DoubleAnimation>
<DoubleAnimation Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(TransformGroup.Children)[1].(ScaleTransform.ScaleX)" BeginTime="00:00:00.2" Duration="00:00:00.1" To="0">
<DoubleAnimation.EasingFunction>
<QuinticEase EasingMode="EaseInOut"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
“By”值,在运行时调试时为空。为什么不应该在这里绑定工作?有什么解决方法吗?在后面的代码中手动设置该值当然可以......但是很好......
m_MyAnimation = (Storyboard)Resources["MyKey"];
((DoubleAnimation)m_MyAnimation.Children[0]).By = ((MyClass.RealHeight - MyClass.RealWidth) / 2D) + MyClass.MarginInner + MyClass.RealWidth;