溢出!
我想为 WP 编写一个变量 Animation。
我用 Expression Blend 像这样创建了动画:
<Storyboard x:Name="rotateC">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)" Storyboard.TargetName="currentDeviancePointer_s">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="10"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
现在我想将第二个值绑定到一个变量。
我找到了 Dependency Properties 的教程并进行了尝试。我的代码编译并运行,但没有任何反应:(
这是我所做的:
创建的依赖对象:
public class RotateClass : DependencyObject
{
public static readonly DependencyProperty NewAngleProperty =
DependencyProperty.Register("newAngle", typeof(double), typeof(RotateClass), new PropertyMetadata(10.0));
public double newAngle
{
get
{
return (double)GetValue(NewAngleProperty);
}
set
{
SetValue(NewAngleProperty, (double)value);
}
}
}
创建了一个对象:
public MainPage()
{
InitializeComponent();
...
angleContainer= new RotateClass();
...
}
我创建了一个带有以下处理程序的按钮:
angleContainer.newAngle = 45;
if (rotateC.GetCurrentState() != ClockState.Active)
{
rotateC.Begin();
}
这是我的绑定:
<Storyboard x:Name="rotateC">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)" Storyboard.TargetName="currentDeviancePointer_s">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="{Binding ElementName=angleContainer,Path=newAngle}"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
有什么错误吗?
也许我这样做太难了?还有其他解决方案吗?谢谢您的帮助!