So, I have a pointer that I made that will animate either clockwise or counterclockwise. Each so often, new data arrives at the two dependency properties that I set. When the data in these properties change, I want to do some calculations for both values to determine which direction (and how much) the calibration needle will rotate.
I have a rotation code, I wrote a function (all in C #) that takes a start angle, an end angle, and a rotation duration. The rotation function works, I can insert values and observe the rotation of the needle.
What I can’t understand how to do this is to call this animation function when any of the dependency properties changes. It would be impractical to set my rotation function, because rotation calls may be instance specific.
In other words, what I would like to achieve is PropertyChanged-> compute the layout of the new positions / speed → build and start the animation.
My discussion about the presence of dependency properties instead of the standard properties is due to the fact that they are connected out of control from xaml.
Thank!
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);
}
source
share