我需要一些帮助来将对象设置为圆形路径。为此,我在Method
中创建了一些LoadEvent
但我不知道在此代码中添加Storyboard
。
Storyboard
应更改循环路径中Object
的位置。
圆形路径由AngelToPointMethod
计算。
如果我SetTargetProperty
到TranslateX
和TranslateY
我的控件移到直接路径但我需要天使移动天使。
这里是我的代码
public class Test : Canvas
{
private int StartAngle = 215;
private Rectangle _myControl = new Rectangle();
private double _angle;
public double Angle
{
get { return _angle;}
set {_angle = value;}
}
public Test()
{
Loaded += OnLoaded;
}
private void OnLoaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
// UpdatePosition(_myControl, StartAngle);
AnimatePositionAtTheFrist(StartOuterAngle);
}
static void OnPropertyChanged(DependencyObject obj,
DependencyPropertyChangedEventArgs args)
{
(obj as CircularSliderControl).OnPropertyChanged(args);
}
void OnPropertyChanged(DependencyPropertyChangedEventArgs args)
{
UpdatePosition(_myControl, StartAngle);
}
private void AnimatePositionAtTheFrist( int startAngle)
{
Duration duration = new Duration(TimeSpan.FromSeconds(1));
Storyboard sb = new Storyboard();
sb.Duration = duration;
//var da = new DoubleAnimationUsingKeyFrames();
var da = new DoubleAnimation();
da.EnableDependentAnimation = true;
da.Duration = duration;
da.From = 0;
da.To = startAngle;
SineEase easingFunction = new SineEase();
easingFunction.EasingMode = EasingMode.EaseOut;
da.EasingFunction = easingFunction;
Storyboard.SetTarget(da, this);
Storyboard.SetTargetProperty(da, "Angle"); // error: Cannot resolve TargetProperty Angle on specified object.
sb.Children.Add(da);
sb.Begin();
}
private void UpdatePosition(Rectangle _myControl, int StartAngle)
{
var startPoint = AngelToPoint(StartAngle);
var tr = new CompositeTransform();
tr.TranslateX = startPoint.X;
tr.TranslateY = startPoint.Y ;
_myControl.RenderTransform = tr;
}
}
我更新了我的代码如上所述,但我遇到了两个新问题
1:如何处理propertyChanged
属性的Angle
?
我做过的实施,对吧?
我需要在UpdatePosition
的更改值不是所有属性时运行Angle
。
2:如何SetTargetProperty
到Angle
属性?