Ejemplo n.º 1
0
        public override void OnApplyTemplate()
        {
            if (_button != null)
            {
                _button.Click -= OnClick;
            }

            base.OnApplyTemplate();

            _root = MoreVisualTreeExtensions.FindFirstChildOfType <Grid>(this);
            if (null == _root)
            {
                throw new NotSupportedException("Must include a Grid for manipulating.");
            }

            _button = GetTemplateChild("_button") as Button;
            if (_button != null)
            {
                _button.Click += OnClick;
            }

            TransformAnimator.EnsureAnimator(_root, ref _ta);
            OpacityAnimator.EnsureAnimator(_root, ref _oa);
            if (_oa != null)
            {
                _root.Opacity = 0;
                _oa.GoTo(1.0, new Duration(TimeSpan.FromSeconds(.5)));
            }
        }
 /// <summary>
 /// Ensures and creates if needed the animator for an element. Will also
 /// verify that a translate transform is present.
 /// </summary>
 /// <param name="targetElement">The target element.</param>
 /// <param name="animator">The animator reference.</param>
 public static void EnsureAnimator(FrameworkElement targetElement, ref TransformAnimator animator)
 {
     if (animator == null)
     {
         TranslateTransform transform = TransformAnimator.GetTranslateTransform(targetElement);
         if (transform != null)
         {
             animator = new TransformAnimator(transform);
         }
     }
     if (animator == null)
     {
         throw new InvalidOperationException("The animation system could not be prepared for the target element.");
     }
 }
Ejemplo n.º 3
0
        protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
        {
            TransformAnimator.EnsureAnimator(_root, ref _ta);
            if (_ta != null)
            {
                _ta.GoTo(e.CumulativeManipulation.Translation.X, new Duration(TimeSpan.FromMilliseconds(20)));
            }

            // Ignore a click now.
            if (_wasClicked && e.DeltaManipulation.Translation.X > 1)
            {
                _wasClicked = false;
            }

            base.OnManipulationDelta(e);
        }
Ejemplo n.º 4
0
        protected override void OnManipulationCompleted(ManipulationCompletedEventArgs e)
        {
            // Flick off-screen.
            if (e.IsInertial && e.TotalManipulation.Translation.X > 0)
            {
                _wasClicked = false;

                TransformAnimator.EnsureAnimator(_root, ref _ta);
                if (_ta != null)
                {
                    _ta.GoTo(ActualWidth + 1.0, new Duration(TimeSpan.FromSeconds(.5)), _ease, OnClosed);
                }
                else
                {
                    OnClosed();
                }
            }
            else if (e.TotalManipulation.Translation.X > 20)
            {
                // Resetting, so if they clicked, forget it.
                if (_wasClicked && e.TotalManipulation.Translation.X > 20)
                {
                    _wasClicked = false;
                }

                // Return and RESET the timer.
                TransformAnimator.EnsureAnimator(_root, ref _ta);
                ResetTimer(); // don't fire yet.
                if (_ta != null)
                {
                    _ta.GoTo(0.0, new Duration(TimeSpan.FromSeconds(.5)), _ease, ResetTimer); // reset once back.
                }
            }
            else
            {
                // A click!
                _wasClicked = true;
                OnTick(this, EventArgs.Empty);
            }

            base.OnManipulationCompleted(e);
        }
Ejemplo n.º 5
0
        public void Restart()
        {
            bool wasValue = _imageOpened;
            _imageOpened = false;
            // clear out immediately
            UpdateVisualStates(false);
            _imageOpened = wasValue;

            if (_imageOpened)
            {
                if (_ta == null)
                {
                    TransformAnimator.EnsureAnimator(_image, ref _ta);
                }
                if (_ta != null)
                {
                    _ta.Forever();

                    var frameWidth = _frame.ActualWidth;
                    var imageWidth = _image.ActualWidth;

                    var finalOffset = imageWidth - frameWidth;
                    if (finalOffset < 0)
                    {
                        // Threw an IOE in the past, someone hit this one
                        // according to some crash reports.
                        finalOffset = 0;
                    }

                    _ta.GoTo(-finalOffset, new Duration(TimeSpan.FromSeconds(50)));
                }

            }

            UpdateVisualStates(true);
        }
 /// <summary>
 /// Ensures and creates if needed the animator for an element. Will also
 /// verify that a translate transform is present.
 /// </summary>
 /// <param name="targetElement">The target element.</param>
 /// <param name="animator">The animator reference.</param>
 public static void EnsureAnimator(FrameworkElement targetElement, ref TransformAnimator animator)
 {
     if (animator == null)
     {
         TranslateTransform transform = TransformAnimator.GetTranslateTransform(targetElement);
         if (transform != null)
         {
             animator = new TransformAnimator(transform);
         }
     }
     if (animator == null)
     {
         throw new InvalidOperationException("The animation system could not be prepared for the target element.");
     }
 }