【发布时间】:2023-03-04 20:24:01
【问题描述】:
溢出!
我想为 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>
有什么错误吗?
也许我这样做太难了?还有其他解决方案吗? 感谢您的帮助!
【问题讨论】:
-
为什么你有一个扩展
DependencyObject的类...你不能简单地绑定到DependencyProperty吗?你在使用 MVVM 吗?有什么框架吗? -
我刚刚安装了 WP8 SDK。没什么特别的。我也试过只使用依赖属性,不使用任何类,但它不起作用。
标签: c# animation windows-phone dependency-properties expression-blend