private bool TryGetSmartStatus()
        {
            var cp = ContentPresenter;

            if (cp == null)
            {
                return(false);
            }

            var descendantsOnce = cp
                                  .GetVisualDescendants()
                                  .ToList();

            _pauseAndResumeChild = descendantsOnce.OfType <ISupportPauseResume>().FirstOrDefault();

            _loadStatusObject = descendantsOnce.OfType <ISendLoadStatus>().FirstOrDefault();

            // If the bindings never get applied due to visibility converters.
            var uie = _loadStatusObject as UIElement;

            if (uie != null && uie.Visibility == Visibility.Collapsed)
            {
                _loadStatusObject = null;
            }

            if (_loadStatusObject == null)
            {
                // Pause and resume is not support for these two.
                var fe = descendantsOnce
                         .OfType <ItemsControl>()
                         .Where(it => it.ItemsSource is ISendLoadStatus)
                         .FirstOrDefault();
                if (fe != null)
                {
                    _loadStatusObject = (ISendLoadStatus)fe.ItemsSource;
                }

                if (_loadStatusObject == null)
                {
                    var de = descendantsOnce
                             .OfType <FrameworkElement>()
                             .Where(ff => ff.DataContext is ISendLoadStatus)
                             .FirstOrDefault();
                    if (de != null)
                    {
                        _loadStatusObject = de.DataContext as ISendLoadStatus;
                    }
                }
            }

            return(_loadStatusObject != null);
        }
Example #2
0
        private void FinallyShowContent()
        {
            Debug.WriteLine("FinallyShowContent");
            if (!_contentPresenterUnloaded)
            {
                _loadingProcessDone = true;

                // No longer need this reference. Do still want resume though!
                //_advancedWaitingElement = null;
                _dataStatusElement = null;

                if (_loadingGrid != null)
                {
                    if (_progressBar != null)
                    {
                        _progressBar.IsIndeterminate = false;
                        _progressBar.Visibility      = Visibility.Collapsed;
                    }

                    AfterFadeOut();
                }

                _contentPresenter.IsHitTestVisible = true;

                // Fade in the new content
                if (_contentGrid != null)
                {
                    MyOpacityAnimator cg = null;
                    MyOpacityAnimator.EnsureAnimator(_contentGrid, ref cg);
                    if (cg != null)
                    {
                        cg.GoTo(1, TransitionDuration);
                    }
                    else
                    {
                        _contentGrid.Opacity = 1;
                    }
                }
            }
        }
Example #3
0
//        private void WaitForSpecializedContent()
//        {
////#if DEBUG_LOADING_PIVOT_ITEM
//            //Debug.WriteLine("     ... but the data isn't ready yet.");
////#endif
//            if (!_contentPresenterUnloaded)
//            {
//                if (_advancedWaitingElement.IsLoadComplete)
//                {
//                    DelayedDispatcherTimer.BeginInvoke(AdditionalLoadTime, FinallyShowContent);
//                }
//                else
//                {
//                    DelayedDispatcherTimer.BeginInvoke(SmartLoadingDelayingTime, WaitForSpecializedContent);
//                }
//            }
//        }

        private void TryTransitionToContent()
        {
            if (_contentPresenterUnloaded)
            {
                return;
            }

//#if DEBUG_LOADING_PIVOT_ITEM
            //Debug.WriteLine("LPI: DataContext of {0} is set to {1}", Header.ToString(), DataContext.ToString());
//#endif

            // Visuals first to grab any control.
            var descendantsOnce = _contentPresenter.GetVisualDescendants().ToList();

            _pauseAndResumeChild = descendantsOnce.OfType <ISupportPauseResume>().FirstOrDefault();
            //_advancedWaitingElement = descendantsOnce.OfType<ISendLoadComplete>().FirstOrDefault();
            _dataStatusElement = descendantsOnce.OfType <ISendLoadStatus>().FirstOrDefault();

            // If the bindings never get applied due to visibility converters.
            //var uie = _advancedWaitingElement as UIElement;
            var uie = _dataStatusElement as UIElement;

            if (uie != null && uie.Visibility == Visibility.Collapsed)
            {
                _dataStatusElement = null;
                //_advancedWaitingElement = null;
            }

            if (_dataStatusElement /*_advancedWaitingElement */ == null)
            {
                // Pause and resume is not support for these two.
                var fe =
                    descendantsOnce.OfType <ItemsControl>().Where(it => it.ItemsSource is ISendLoadStatus).
                    FirstOrDefault();
                if (fe != null)
                {
                    _dataStatusElement = (ISendLoadStatus)fe.ItemsSource;
                    //_advancedWaitingElement = (ISendLoadComplete) fe.ItemsSource;
                }

                if (_dataStatusElement /*_advancedWaitingElement */ == null)
                {
                    var de =
                        descendantsOnce.OfType <FrameworkElement>().Where(ff => ff.DataContext is ISendLoadStatus)
                        .FirstOrDefault();
                    if (de != null)
                    {
                        _dataStatusElement = de.DataContext as ISendLoadStatus;
//                        _advancedWaitingElement = de.DataContext as ISendLoadComplete;
                    }
                }
            }

            if (_dataStatusElement /*_advancedWaitingElement */ != null)
            {
#if DEBUG_LOADING_PIVOT_ITEM
                Debug.WriteLine("LPI: Custom item base {0} supports load notifications. Excellent.", _dataStatusElement.GetType().ToString());
#endif
//                if (_advancedWaitingElement.IsLoadComplete)
                if (_dataStatusElement.LoadStatus == LoadStatus.Loaded || _dataStatusElement.LoadStatus == LoadStatus.Failed)
                {
                    OnceSpecializedContentIsReady();
                }
                else
                {
                    _dataStatusElement.LoadStatusChanged += OnAdvancedWaitingElementLoadComplete;
                    //_advancedWaitingElement.LoadComplete += OnAdvancedWaitingElementLoadComplete;
                    //return;
                }

                // don't let it appear by accident...
                return;
            }

            Debug.Assert(!_contentPresenterUnloaded);

            DelayedDispatcherTimer.BeginInvoke(AdditionalLoadTime, FinallyShowContent);
        }
        private void FinallyShowContent()
        {
            Debug.WriteLine("FinallyShowContent");
            if (!_contentPresenterUnloaded)
            {
                _loadingProcessDone = true;

                // No longer need this reference. Do still want resume though!
                //_advancedWaitingElement = null;
                _dataStatusElement = null;

                if (_loadingGrid != null)
                {
                    if (_progressBar != null)
                    {
                        _progressBar.IsIndeterminate = false;
                        _progressBar.Visibility = Visibility.Collapsed;
                    }

                    AfterFadeOut();
                }

                _contentPresenter.IsHitTestVisible = true;

                // Fade in the new content
                if (_contentGrid != null)
                {
                    MyOpacityAnimator cg = null;
                    MyOpacityAnimator.EnsureAnimator(_contentGrid, ref cg);
                    if (cg != null)
                    {
                        cg.GoTo(1, TransitionDuration);
                    }
                    else
                    {
                        _contentGrid.Opacity = 1;
                    }
                }
            }
        }
//        private void WaitForSpecializedContent()
//        {
////#if DEBUG_LOADING_PIVOT_ITEM
//            //Debug.WriteLine("     ... but the data isn't ready yet.");
////#endif
//            if (!_contentPresenterUnloaded)
//            {
//                if (_advancedWaitingElement.IsLoadComplete)
//                {
//                    DelayedDispatcherTimer.BeginInvoke(AdditionalLoadTime, FinallyShowContent);
//                }
//                else
//                {
//                    DelayedDispatcherTimer.BeginInvoke(SmartLoadingDelayingTime, WaitForSpecializedContent);
//                }
//            }
//        }

        private void TryTransitionToContent()
        {
            if (_contentPresenterUnloaded)
            {
                return;
            }

//#if DEBUG_LOADING_PIVOT_ITEM
            //Debug.WriteLine("LPI: DataContext of {0} is set to {1}", Header.ToString(), DataContext.ToString());
//#endif

            // Visuals first to grab any control.
            var descendantsOnce = _contentPresenter.GetVisualDescendants().ToList();
            _pauseAndResumeChild = descendantsOnce.OfType<ISupportPauseResume>().FirstOrDefault();
            //_advancedWaitingElement = descendantsOnce.OfType<ISendLoadComplete>().FirstOrDefault();
            _dataStatusElement = descendantsOnce.OfType<ISendLoadStatus>().FirstOrDefault();

            // If the bindings never get applied due to visibility converters.
            //var uie = _advancedWaitingElement as UIElement;
            var uie = _dataStatusElement as UIElement;
            if (uie != null && uie.Visibility == Visibility.Collapsed)
            {
                _dataStatusElement = null;
                //_advancedWaitingElement = null;
            }

            if (_dataStatusElement /*_advancedWaitingElement */== null)
            {
                // Pause and resume is not support for these two.
                var fe =
                    descendantsOnce.OfType<ItemsControl>().Where(it => it.ItemsSource is ISendLoadStatus).
                        FirstOrDefault();
                if (fe != null)
                {
                    _dataStatusElement = (ISendLoadStatus)fe.ItemsSource;
                    //_advancedWaitingElement = (ISendLoadComplete) fe.ItemsSource;
                }

                if (_dataStatusElement /*_advancedWaitingElement */ == null)
                {
                    var de =
                        descendantsOnce.OfType<FrameworkElement>().Where(ff => ff.DataContext is ISendLoadStatus)
                            .FirstOrDefault();
                    if (de != null)
                    {
                        _dataStatusElement = de.DataContext as ISendLoadStatus;
//                        _advancedWaitingElement = de.DataContext as ISendLoadComplete;
                    }
                }
            }

            if (_dataStatusElement/*_advancedWaitingElement */!= null)
            {
#if DEBUG_LOADING_PIVOT_ITEM
                Debug.WriteLine("LPI: Custom item base {0} supports load notifications. Excellent.", _dataStatusElement.GetType().ToString());
#endif
//                if (_advancedWaitingElement.IsLoadComplete)
                if (_dataStatusElement.LoadStatus == LoadStatus.Loaded || _dataStatusElement.LoadStatus == LoadStatus.Failed)
                {
                    OnceSpecializedContentIsReady();
                }
                else
                {
                    _dataStatusElement.LoadStatusChanged += OnAdvancedWaitingElementLoadComplete;
                    //_advancedWaitingElement.LoadComplete += OnAdvancedWaitingElementLoadComplete;
                    //return;
                }

                // don't let it appear by accident...
                return;
            }

            Debug.Assert(!_contentPresenterUnloaded);

            DelayedDispatcherTimer.BeginInvoke(AdditionalLoadTime, FinallyShowContent);
        }
        private bool TryGetSmartStatus()
        {
            var cp = ContentPresenter;
            if (cp == null)
            {
                return false;
            }

            var descendantsOnce = cp
                .GetVisualDescendants()
                .ToList();

            _pauseAndResumeChild = descendantsOnce.OfType<ISupportPauseResume>().FirstOrDefault();

            _loadStatusObject = descendantsOnce.OfType<ISendLoadStatus>().FirstOrDefault();

            // If the bindings never get applied due to visibility converters.
            var uie = _loadStatusObject as UIElement;
            if (uie != null && uie.Visibility == Visibility.Collapsed)
            {
                _loadStatusObject = null;
            }

            if (_loadStatusObject == null)
            {
                // Pause and resume is not support for these two.
                var fe = descendantsOnce
                    .OfType<ItemsControl>()
                    .Where(it => it.ItemsSource is ISendLoadStatus)
                    .FirstOrDefault();
                if (fe != null)
                {
                    _loadStatusObject = (ISendLoadStatus)fe.ItemsSource;
                }

                if (_loadStatusObject == null)
                {
                    var de = descendantsOnce
                        .OfType<FrameworkElement>()
                        .Where(ff => ff.DataContext is ISendLoadStatus)
                        .FirstOrDefault();
                    if (de != null)
                    {
                        _loadStatusObject = de.DataContext as ISendLoadStatus;
                    }
                }
            }

            return (_loadStatusObject != null);
        }