WPF - 애니메이션 StoryBoard를 중지할 수 없으며 IsControllable이 작동하지 않습니까?

StackOverflow https://stackoverflow.com/questions/696534

  •  22-08-2019
  •  | 
  •  

문제

공유 스토리보드를 사용하여 애니메이션을 적용하는 3D 큐브가 있습니다.애니메이션 코드는 콤보박스의 SelectionChanged 이벤트에 있으며 아직 실행 중인 애니메이션이 다음 애니메이션이 시작되기 전에 중지되도록 하기 위한 것입니다.하지만 그렇게 작동하지 않습니다!

나는 이것이 꽤 지저분한 코드라는 것을 알고 있지만 .begin(this,true)을 호출하고 있기 때문에 내 스토리보드가 제어에 응답하지 않는 이유를 여전히 알 수 없습니다.

누군가 내가 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;
        }
    }
}
도움이 되었습니까?

해결책

나는 이것을 시작 메소드에 전달하는 대신 cbo를 전달해야 한다고 생각합니다.

이것은 현재 클래스(창 클래스인 것 같아요)를 참조하는 반면, 애니메이션을 제어하기 위한 cbo의 변경 사항입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top