Esempio n. 1
0
        // instead of using content named parts, it is possible to anime a property
        // then bound in the content file (see Button3D.PressEffect).

        //public double FrameRingAngle
        //{
        //    get { return (double)GetValue(FrameRingAngleProperty); }
        //    set { SetValue(FrameRingAngleProperty, value); }
        //}

        //// Using a DependencyProperty as the backing store for FrameRingAngle.  This enables animation, styling, binding, etc...
        //public static readonly DependencyProperty FrameRingAngleProperty =
        //    DependencyProperty.Register(
        //        "FrameRingAngle",
        //        typeof(double),
        //        typeof(Gyroscope3D),
        //        new UIPropertyMetadata(0.0));

        /// <summary>
        /// Invoked when an unhandled MouseLeftButtonDown routed event is raised on this element.
        /// </summary>
        /// <param name="e">The MouseButtonEventArgs that contains the event data.</param>
        protected override void OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e)
        {
            if (!_isAnimated)
            {
                // Initialization of the animation objects : on 360 degrees after the current angle
                // _frameRingAngleAnimation.To = FrameRingAngle + 360.0;
                _frameRingAngleAnimation.To = _frameRingRotation.Angle + 360.0;
                _ringModelAngleAnimation.To = _ringModelRotation.Angle + 360.0;
                _rotorAngleAnimation.To     = _rotorRotation.Angle - 360.0;

                // Triggers the animation on the FrameRingAngle property
                //this.ApplyAnimationClock(
                //    FrameRingAngleProperty,
                //    _frameRingAngleAnimation.CreateClock());
                // Triggers the animation on the _frameRingAngleAnimation.Angle property
                _frameRingRotation.ApplyAnimationClock(
                    AxisAngleRotation3D.AngleProperty,
                    _frameRingAngleAnimation.CreateClock());

                // Triggers the animation on the _ringModelRotation.Angle property
                _ringModelRotation.ApplyAnimationClock(
                    AxisAngleRotation3D.AngleProperty,
                    _ringModelAngleAnimation.CreateClock());

                // Triggers the animation on the _rotorRotation.Angle property
                _rotorRotation.ApplyAnimationClock(
                    AxisAngleRotation3D.AngleProperty,
                    _rotorAngleAnimation.CreateClock());
            }
            else
            {
                // current angle memorization
                // double frameRingAngle = FrameRingAngle;
                double frameRingAngle         = _frameRingRotation.Angle;
                double ringModelRotationAngle = _ringModelRotation.Angle;
                double rotorRotationAngle     = _rotorRotation.Angle;

                // Halts the animations
                // this.ApplyAnimationClock(FrameRingAngleProperty, null);
                _frameRingRotation.ApplyAnimationClock(
                    AxisAngleRotation3D.AngleProperty,
                    null);
                _ringModelRotation.ApplyAnimationClock(
                    AxisAngleRotation3D.AngleProperty,
                    null);
                _rotorRotation.ApplyAnimationClock(
                    AxisAngleRotation3D.AngleProperty,
                    null);

                // Reassignment of the angle (which otherwise resumes its initial value)
                _rotorRotation.Angle     = rotorRotationAngle;
                _ringModelRotation.Angle = ringModelRotationAngle;
                _frameRingRotation.Angle = frameRingAngle;
                // FrameRingAngle = frameRingAngle;
            }
            _isAnimated = !_isAnimated;
            base.OnMouseLeftButtonDown(e);
        }