WPF - Не удается остановить анимацию StoryBoard, IsControllable не работает? - PullRequest
4 голосов
/ 30 марта 2009

У меня есть 3D-куб, который я анимирую, используя раскадровку. Код анимации находится в событии selectionChanged в выпадающем списке и предназначен для того, чтобы убедиться, что любая анимация, которая все еще работает, будет остановлена ​​до начала следующей; но это так не работает!

Я понимаю, что это довольно грязный код, но я до сих пор не понимаю, почему моя раскадровка не отвечает на управление, так как я звоню .begin (это правда).

Может кто-нибудь сказать мне, почему я не могу остановить StoryBoard? Я все еще получаю это хитрое 'System.Windows.Media.Animation Warning: 6 : Unable to perform action because the specified Storyboard was never applied to this object for interactive control.; Action='Stop';' сообщение

        Storyboard sb = new Storyboard();
    DoubleAnimation forward90 = new DoubleAnimation(0,90,TimeSpan.FromMilliseconds(2000));
    DoubleAnimation back90 = new DoubleAnimation(0,-90, TimeSpan.FromMilliseconds(2000));

private void cbo_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        forward90.BeginTime = TimeSpan.Zero;
        back90.BeginTime = TimeSpan.Zero;

        NameScope.SetNameScope(this, new NameScope());

        RegisterName(this.Name, this);

        sb.Stop(this);
        sb.Remove(this);

        sb.Children.Clear();

        sb.AccelerationRatio = 0;
        sb.DecelerationRatio = 1;
        sb.RepeatBehavior = RepeatBehavior.Forever;

        int i = cbo.SelectedIndex;
        Orientation o = (Orientation)i;

        ViewModel vm = this.DataContext as ViewModel;
        if(vm !=null)vm.Orient = o;


        switch (o)
        {
            case Orientation.Front0:

                break;
            case Orientation.Front90:

                sb.Children.Add(forward90);

                Storyboard.SetTarget(forward90, cube2);

                Storyboard.SetTargetProperty(forward90, new PropertyPath(CubeControl.CubeControl.XRotationProperty));
                sb.Begin(this, true);

                break;
            case Orientation.Right0:

                sb.Children.Add(back90);

                Storyboard.SetTarget(back90, cube2);

                Storyboard.SetTargetProperty(back90, new PropertyPath(CubeControl.CubeControl.YRotationProperty));
                sb.Begin(this, true);

                break;
            case Orientation.Right90:

                back90.BeginTime = TimeSpan.FromMilliseconds(2000);

                sb.Children.Add(forward90);
                sb.Children.Add(back90);

                Storyboard.SetTarget(back90, cube2);
                Storyboard.SetTarget(forward90, cube2);

                Storyboard.SetTargetProperty(forward90, new PropertyPath(CubeControl.CubeControl.YRotationProperty));
                Storyboard.SetTargetProperty(back90, new PropertyPath(CubeControl.CubeControl.ZRotationProperty));

                sb.Begin(this, true);

                break;
            case Orientation.Top0:

                sb.Children.Add(back90);

                Storyboard.SetTarget(back90, cube2);
                Storyboard.SetTargetProperty(back90, new PropertyPath(CubeControl.CubeControl.ZRotationProperty));
                sb.Begin(this, true);

                break;
            case Orientation.Top90:

                back90.BeginTime = TimeSpan.FromMilliseconds(2000);

                sb.Children.Add(forward90);
                sb.Children.Add(back90);

                Storyboard.SetTarget(forward90, cube2);
                Storyboard.SetTarget(back90, cube2);

                Storyboard.SetTargetProperty(forward90, new PropertyPath(CubeControl.CubeControl.XRotationProperty));
                Storyboard.SetTargetProperty(back90, new PropertyPath(CubeControl.CubeControl.ZRotationProperty));

                sb.Begin(this, true);
                break;
            default:
                break;
        }
    }
}

1 Ответ

3 голосов
/ 31 марта 2009

Я полагаю, вам нужно перейти в cbo, а не в метод begin.

это относится к текущему классу (я полагаю, ваш класс окна), в то время как изменение в cbo заключается в управлении анимацией.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...