/// <summary>
        /// Method called at the end of manipulation to clean up everything
        /// </summary>
        private void OnManipulationCompleted()
        {
            CompositionTarget.Rendering          -= CompositionTarget_Rendering;
            _refreshIndicatorTransform.TranslateY = -_refreshIndicatorBorder.ActualHeight;
            if (_contentTransform != null)
            {
                _contentTransform.TranslateY = 0;
            }

            if (_refreshActivated)
            {
                RefreshRequested?.Invoke(this, new EventArgs());
                if (RefreshCommand != null && RefreshCommand.CanExecute(null))
                {
                    RefreshCommand.Execute(null);
                }
            }

            _lastOffset            = 0;
            _pullDistance          = 0;
            _refreshActivated      = false;
            _lastRefreshActivation = default(DateTime);

            PullProgressChanged?.Invoke(this, new RefreshProgressEventArgs {
                PullProgress = 0
            });
        }
Exemplo n.º 2
0
        private void Scroller_DirectManipulationCompleted(object sender, object e)
        {
            CompositionTarget.Rendering          -= CompositionTarget_Rendering;
            _refreshIndicatorTransform.TranslateY = -_refreshIndicatorBorder.ActualHeight;
            _contentTransform.TranslateY          = 0;

            if (_refreshActivated)
            {
                RefreshRequested?.Invoke(this, new EventArgs());
                if (RefreshCommand != null && RefreshCommand.CanExecute(null))
                {
                    RefreshCommand.Execute(null);
                }
            }

            _refreshActivated      = false;
            _lastRefreshActivation = default(DateTime);

            if (RefreshIndicatorContent == null)
            {
                _defaultIndicatorContent.Text = "Pull to Refresh";
            }

            PullProgressChanged?.Invoke(this, new RefreshProgressEventArgs()
            {
                PullProgress = 0
            });
        }
        /// <summary>
        /// Method called at the end of manipulation to clean up everything
        /// </summary>
        private void OnManipulationCompleted()
        {
            CompositionTarget.Rendering          -= CompositionTarget_Rendering;
            _refreshIndicatorTransform.TranslateY = -_refreshIndicatorBorder.ActualHeight;
            if (_contentTransform != null)
            {
                _contentTransform.TranslateY = 0;

                if (_headerTransform != null)
                {
                    _headerTransform.TranslateY = 0;
                }

                if (_footerTransform != null)
                {
                    _footerTransform.TranslateY = 0;
                }
            }

            if (_refreshActivated)
            {
                RefreshRequested?.Invoke(this, EventArgs.Empty);
                if (RefreshCommand != null && RefreshCommand.CanExecute(null))
                {
                    RefreshCommand.Execute(null);
                }
            }
            else if (_refreshIntentCanceled)
            {
                RefreshIntentCanceled?.Invoke(this, EventArgs.Empty);
                if (RefreshIntentCanceledCommand != null && RefreshIntentCanceledCommand.CanExecute(null))
                {
                    RefreshIntentCanceledCommand.Execute(null);
                }
            }

            _lastOffset              = 0;
            _pullDistance            = 0;
            _refreshActivated        = false;
            _refreshIntentCanceled   = false;
            _lastRefreshActivation   = default(DateTime);
            _isManipulatingWithMouse = false;

            PullProgressChanged?.Invoke(this, new RefreshProgressEventArgs {
                PullProgress = 0
            });
            _pullAndReleaseIndicatorContent.Content = null;
        }
        private void CompositionTarget_Rendering(object sender, object e)
        {
            // if started navigating down, cancel the refresh
            if (_scroller.VerticalOffset > 1)
            {
                CompositionTarget.Rendering          -= CompositionTarget_Rendering;
                _refreshIndicatorTransform.TranslateY = -_refreshIndicatorBorder.ActualHeight;
                if (_contentTransform != null)
                {
                    _contentTransform.TranslateY = 0;
                }

                _refreshActivated      = false;
                _lastRefreshActivation = default(DateTime);

                PullProgressChanged?.Invoke(this, new RefreshProgressEventArgs {
                    PullProgress = 0
                });
                _isManipulatingWithMouse = false;

                return;
            }

            if (_contentTransform == null)
            {
                var itemScrollPanel = _scrollerContent.FindDescendant <Panel>();
                if (itemScrollPanel == null)
                {
                    return;
                }

                _contentTransform = new CompositeTransform();
                itemScrollPanel.RenderTransform = _contentTransform;
            }

            Rect elementBounds = _scrollerContent.TransformToVisual(_root).TransformBounds(default(Rect));

            // content is not "moved" automagically by the scrollviewer in this case
            // so we apply our own transformation too and need to take it in account.
            if (_isManipulatingWithMouse)
            {
                elementBounds = _contentTransform.TransformBounds(elementBounds);
            }

            var offset = elementBounds.Y;
            var delta  = offset - _lastOffset;

            _lastOffset = offset;

            _pullDistance += delta * _overscrollMultiplier;

            if (_isManipulatingWithMouse)
            {
                _pullDistance = 2 * offset;
            }

            if (_pullDistance > 0)
            {
                if (!_isManipulatingWithMouse)
                {
                    _contentTransform.TranslateY = _pullDistance - offset;
                }

                _refreshIndicatorTransform.TranslateY = _pullDistance - offset
                                                        - _refreshIndicatorBorder.ActualHeight;
            }
            else
            {
                if (!_isManipulatingWithMouse)
                {
                    _contentTransform.TranslateY = 0;
                }

                _refreshIndicatorTransform.TranslateY = -_refreshIndicatorBorder.ActualHeight;
            }

            double pullProgress;

            if (_pullDistance >= PullThreshold)
            {
                _lastRefreshActivation = DateTime.Now;
                _refreshActivated      = true;
                pullProgress           = 1.0;
                if (RefreshIndicatorContent == null)
                {
                    if (_defaultIndicatorContent != null)
                    {
                        _defaultIndicatorContent.Text = ReleaseToRefreshLabel;
                    }

                    if (_pullAndReleaseIndicatorContent != null)
                    {
                        _pullAndReleaseIndicatorContent.Content = ReleaseToRefreshContent;
                    }
                }
            }
            else if (_lastRefreshActivation != DateTime.MinValue)
            {
                TimeSpan timeSinceActivated = DateTime.Now - _lastRefreshActivation;

                // if more then a second since activation, deactivate
                if (timeSinceActivated.TotalMilliseconds > 1000)
                {
                    _refreshActivated      = false;
                    _lastRefreshActivation = default(DateTime);
                    pullProgress           = _pullDistance / PullThreshold;
                    if (RefreshIndicatorContent == null)
                    {
                        if (_defaultIndicatorContent != null)
                        {
                            _defaultIndicatorContent.Text = PullToRefreshLabel;
                        }

                        if (_pullAndReleaseIndicatorContent != null)
                        {
                            _pullAndReleaseIndicatorContent.Content = PullToRefreshContent;
                        }
                    }
                }
                else
                {
                    pullProgress = 1.0;
                }
            }
            else
            {
                pullProgress = _pullDistance / PullThreshold;
            }

            PullProgressChanged?.Invoke(this, new RefreshProgressEventArgs {
                PullProgress = pullProgress
            });
        }
Exemplo n.º 5
0
        private void CompositionTarget_Rendering(object sender, object e)
        {
            // if started navigating down, cancel the refresh
            if (ScrollViewer.VerticalOffset > 1)
            {
                CompositionTarget.Rendering         -= CompositionTarget_Rendering;
                RefreshIndicatorTransform.TranslateY = -RefreshIndicator.ActualHeight;
                if (_contentTransform != null)
                {
                    _contentTransform.TranslateY = 0;
                }

                _refreshActivated      = false;
                _lastRefreshActivation = default(DateTime);

                PullProgressChanged?.Invoke(this, new RefreshProgressEventArgs {
                    PullProgress = 0
                });
                _isManipulatingWithMouse = false;

                return;
            }

            if (_contentTransform == null)
            {
                var itemsPanel = VisualTreeHelper.GetChild(MainContent as UIElement, 0) as UIElement;
                //var headerContent = VisualTreeHelper.GetChild(MainContent, 0) as UIElement;
                //var itemsPanel = VisualTreeHelper.GetChild(MainContent, 1) as UIElement;
                //var footerContent = VisualTreeHelper.GetChild(MainContent, 2) as UIElement;

                //if (_headerTransform == null && VisualTreeHelper.GetChildrenCount(headerContent) > 0)
                //{
                //    if (headerContent != null)
                //    {
                //        _headerTransform = new CompositeTransform();
                //        headerContent.RenderTransform = _headerTransform;
                //    }
                //}

                //if (_footerTransform == null && VisualTreeHelper.GetChildrenCount(footerContent) > 0)
                //{
                //    if (footerContent != null)
                //    {
                //        _footerTransform = new CompositeTransform();
                //        footerContent.RenderTransform = _footerTransform;
                //    }
                //}

                if (itemsPanel == null)
                {
                    return;
                }

                _contentTransform          = new CompositeTransform();
                itemsPanel.RenderTransform = _contentTransform;
            }

            Rect elementBounds = (MainContent as UIElement).TransformToVisual(Root).TransformBounds(default(Rect));

            // content is not "moved" automagically by the scrollviewer in this case
            // so we apply our own transformation too and need to take it in account.
            if (_isManipulatingWithMouse)
            {
                elementBounds = _contentTransform.TransformBounds(elementBounds);
            }

            var offset = elementBounds.Y;
            var delta  = offset - _lastOffset;

            _lastOffset = offset;

            _pullDistance += delta * _overscrollMultiplier;

            if (_isManipulatingWithMouse)
            {
                _pullDistance = 2 * offset;
            }

            if (_pullDistance > 0)
            {
                if (!_isManipulatingWithMouse)
                {
                    _contentTransform.TranslateY = _pullDistance - offset;
                }

                if (_isManipulatingWithMouse)
                {
                    RefreshIndicatorTransform.TranslateY = _pullDistance - offset
                                                           - RefreshIndicator.ActualHeight;
                }
                else
                {
                    RefreshIndicatorTransform.TranslateY = _pullDistance
                                                           - RefreshIndicator.ActualHeight;
                }
            }
            else
            {
                if (!_isManipulatingWithMouse)
                {
                    _contentTransform.TranslateY = 0;
                }

                RefreshIndicatorTransform.TranslateY = -RefreshIndicator.ActualHeight;
            }

            double pullProgress;

            if (_pullDistance >= PullThreshold)
            {
                _lastRefreshActivation = DateTime.Now;
                _refreshActivated      = true;
                _refreshIntentCanceled = false;
                pullProgress           = 1.0;
                if (RefreshIndicatorContent == null)
                {
                    if (PullAndReleaseIndicatorContent != null)
                    {
                        PullAndReleaseIndicatorContent.Content = ReleaseToRefreshContent;
                    }
                }
            }
            else if (_lastRefreshActivation != DateTime.MinValue)
            {
                TimeSpan timeSinceActivated = DateTime.Now - _lastRefreshActivation;

                // if more then a second since activation, deactivate
                if (timeSinceActivated.TotalMilliseconds > 1000)
                {
                    _refreshIntentCanceled |= _refreshActivated;
                    _refreshActivated       = false;
                    _lastRefreshActivation  = default(DateTime);
                    pullProgress            = _pullDistance / PullThreshold;
                    if (RefreshIndicatorContent == null)
                    {
                        if (PullAndReleaseIndicatorContent != null)
                        {
                            PullAndReleaseIndicatorContent.Content = PullToRefreshContent;
                        }
                    }
                }
                else
                {
                    pullProgress            = 1.0;
                    _refreshIntentCanceled |= _refreshActivated;
                }
            }
            else
            {
                pullProgress            = _pullDistance / PullThreshold;
                _refreshIntentCanceled |= _refreshActivated;
            }

            PullProgressChanged?.Invoke(this, new RefreshProgressEventArgs {
                PullProgress = pullProgress
            });
        }
        private void CompositionTarget_Rendering(object sender, object e)
        {
            // if started navigating down, cancel the refresh
            if (_scroller.VerticalOffset > 1)
            {
                CompositionTarget.Rendering          -= CompositionTarget_Rendering;
                _refreshIndicatorTransform.TranslateY = -_refreshIndicatorBorder.ActualHeight;
                if (_contentTransform != null)
                {
                    _contentTransform.TranslateY = 0;
                }

                _refreshActivated      = false;
                _lastRefreshActivation = default(DateTime);

                PullProgressChanged?.Invoke(this, new RefreshProgressEventArgs()
                {
                    PullProgress = 0
                });

                return;
            }

            if (_contentTransform == null)
            {
                var itemScrollPanel = _scrollerContent.FindDescendant <Panel>();
                if (itemScrollPanel == null)
                {
                    return;
                }

                _contentTransform = new CompositeTransform();
                itemScrollPanel.RenderTransform = _contentTransform;
            }

            Rect elementBounds = _scrollerContent.TransformToVisual(_root).TransformBounds(default(Rect));

            var offset = elementBounds.Y;
            var delta  = offset - _lastOffset;

            _lastOffset = offset;

            _pullDistance += delta * _overscrollMultiplier;

            if (_pullDistance > 0)
            {
                _contentTransform.TranslateY          = _pullDistance - offset;
                _refreshIndicatorTransform.TranslateY = _pullDistance - offset - _refreshIndicatorBorder.ActualHeight;
            }
            else
            {
                _contentTransform.TranslateY          = 0;
                _refreshIndicatorTransform.TranslateY = -_refreshIndicatorBorder.ActualHeight;
            }

            var pullProgress = 0.0;

            if (_pullDistance >= PullThreshold)
            {
                _lastRefreshActivation = DateTime.Now;
                _refreshActivated      = true;
                pullProgress           = 1.0;
                if (RefreshIndicatorContent == null)
                {
                    _defaultIndicatorContent.Text = ReleaseToRefreshLabel;
                }
            }
            else if (_lastRefreshActivation != DateTime.MinValue)
            {
                TimeSpan timeSinceActivated = DateTime.Now - _lastRefreshActivation;

                // if more then a second since activation, deactivate
                if (timeSinceActivated.TotalMilliseconds > 1000)
                {
                    _refreshActivated      = false;
                    _lastRefreshActivation = default(DateTime);
                    pullProgress           = _pullDistance / PullThreshold;
                    if (RefreshIndicatorContent == null)
                    {
                        _defaultIndicatorContent.Text = PullToRefreshLabel;
                    }
                }
                else
                {
                    pullProgress = 1.0;
                }
            }
            else
            {
                pullProgress = _pullDistance / PullThreshold;
            }

            if (PullProgressChanged != null)
            {
                PullProgressChanged(this, new RefreshProgressEventArgs()
                {
                    PullProgress = pullProgress
                });
            }
        }