所以我有一个我已制作的仪表,可以顺时针或逆时针方向制作动画.每隔一段时间,新数据就会进入我设置的两个依赖属性.当这些属性中的数据发生变化时,我想对两个值进行一些计算,以确定仪表针的旋转方向(以及多少).
我有旋转代码工作,我写了一个函数(全部用C#),它取旋转的起始角度,结束角度和持续时间.旋转功能起作用,我可以将值放入并观察针旋转.
我无法弄清楚怎么做是在任何一个依赖属性改变时调用这个动画函数.将旋转函数设置为静态是不合适的,因为旋转调用最终可能是特定于实例的.
换句话说,我想要实现的是PropertyChanged->计算新位置/速度 - >构建故事板并运行动画.
我有依赖属性而不是标准属性的原因是因为它们被xaml绑定到控件之外.
谢谢!
private void AnimatePointer(double startAngle, double endAngle, TimeSpan length, string pointerName)
{
DoubleAnimation handRotation = new DoubleAnimation();
handRotation.From = startAngle;
handRotation.To = endAngle;
handRotation.Duration = new Duration(length);
Storyboard.SetTargetName(handRotation, pointerName);
DependencyProperty[] propertyChain =
new DependencyProperty[]
{
Rectangle.RenderTransformProperty,
TransformGroup.ChildrenProperty,
RotateTransform.AngleProperty
};
string anglePath = "(0).(1)[1].(2)";
PropertyPath propPath = new PropertyPath(anglePath, propertyChain);
Storyboard.SetTargetProperty(handRotation, propPath);
Storyboard sb = new Storyboard();
sb.Children.Add(handRotation);
sb.Begin(this);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2007 次 |
| 最近记录: |