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))); } }
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); }
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); }
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); }