在代码中使用故事板在winrt

时间:2015-08-24 02:00:10

标签: c# animation windows-runtime windows-phone-8.1 storyboard

我需要一些帮助来将对象设置为圆形路径。为此,我在Method中创建了一些LoadEvent但我不知道在此代码中添加StoryboardStoryboard应更改循环路径中Object的位置。 圆形路径由AngelToPointMethod计算。 如果我SetTargetPropertyTranslateXTranslateY我的控件移到直接路径但我需要天使移动天使。

这里是我的代码

 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:如何SetTargetPropertyAngle属性?

0 个答案:

没有答案