Beispiel #1
0
 /// <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 TransformYAnimator animator)
 {
     if (animator == null)
     {
         TranslateTransform transform = TransformYAnimator.GetTranslateTransform(targetElement);
         if (transform != null)
         {
             animator = new TransformYAnimator(transform);
         }
     }
     if (animator == null)
     {
         throw new InvalidOperationException("The animation system could not be prepared for the target element.");
     }
 }
 /// <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 TransformYAnimator animator)
 {
     if (animator == null)
     {
         TranslateTransform transform = TransformYAnimator.GetTranslateTransform(targetElement);
         if (transform != null)
         {
             animator = new TransformYAnimator(transform);
         }
     }
     if (animator == null)
     {
         throw new InvalidOperationException("The animation system could not be prepared for the target element.");
     }
 }
        public override void OnApplyTemplate()
        {
            if (_scrollViewer != null && IsPullToRefreshEnabled)
            {
                _scrollViewer.ManipulationStarted -= OnManipulationStarted;
            }
            if (_top != null)
            {
                _top.MouseLeftButtonDown -= OnJumpToTop;
            }
            if (_bottom != null)
            {
                _bottom.MouseLeftButtonDown -= OnJumpToBottom;
            }

            _ta = null;
            base.OnApplyTemplate();

            if (IsPullToRefreshEnabled)
            {
                SizeChanged += OnSizeChanged;
            }

            _scrollViewer = MoreVisualTreeExtensions.FindFirstChildOfType<ScrollViewer>(this);
            if (null == _scrollViewer)
            {
                return;
                // Must be at design time.
                //throw new NotSupportedException("Control Template must include a ScrollViewer.");
            }

            Dispatcher.BeginInvoke(() =>
            {
                _top = VisualTreeExtensions.GetVisualDescendants(_scrollViewer).OfType<Rectangle>().Where(b => b.Name == TopJumpName).FirstOrDefault();
                _bottom = VisualTreeExtensions.GetVisualDescendants(_scrollViewer).OfType<Rectangle>().Where(b => b.Name == BottomJumpName).FirstOrDefault();

                if (_top != null)
                {
                    _top.MouseLeftButtonUp += OnJumpToTop;
                }
                if (_bottom != null)
                {
                    _bottom.MouseLeftButtonUp += OnJumpToBottom;
                }
            });

            _header = GetTemplateChild("Header") as ContentPresenter;
            if (_header != null)
            {
                TransformYAnimator.EnsureAnimator(_header, ref _ta);
            }

            if (IsPullToRefreshEnabled)
            {
                _scrollViewer.ManipulationStarted += OnManipulationStarted;
            }

            Dispatcher.BeginInvoke(() =>
            {
                int i = 0;
                UIElement uie = Parent as UIElement;
                while (i < 8 && uie != null && _piv == null)
                {
                    uie = VisualTreeHelper.GetParent(uie) as UIElement;
                    _piv = uie as LoadingPivotItem;
                }

                var implroot = VisualTreeHelper.GetChild(_scrollViewer, 0) as FrameworkElement;
                if (implroot != null)
                {
                    VisualStateGroup group = FindVisualState(implroot, "ScrollStates");
                    if (group != null)
                    {
                        group.CurrentStateChanging += OnScrollingStateChanging;
                        // should probably disconnect too
                    }
                }

                this.InvokeOnLayoutUpdated(Bump);
            });
        }
        public override void OnApplyTemplate()
        {
            if (_ya != null)
            {
                _ya = null;
            }

            if (_pivotItem == null)
            {
                DependencyObject d = Parent;
                while (d != null && !(d is PivotItem))
                {
                    d = VisualTreeHelper.GetParent(d);
                }
                _pivotItem = d as PivotItem;
            }

            if (_pivotItem != null && _pivot == null)
            {
                DependencyObject d = _pivotItem;
                while (d != null && !(d is Pivot))
                {
                    d = VisualTreeHelper.GetParent(d);
                }
                _pivot = d as Pivot;
                if (_pivot != null)
                {
                    _pivot.UnloadingPivotItem += OnUnloadingPivotItem;
                    //_pivot.SelectionChanged += OnPivotSelectionChanged;
                }
            }

            base.OnApplyTemplate();

            _image = GetTemplateChild("_image") as Image;
            _grid = GetTemplateChild("_grid") as Grid;

            TransformYAnimator.EnsureAnimator(_grid, ref _ya);
            Debug.Assert(_ya != null);

            if (_image != null && ImageSource != null)
            {
                UpdateImageSource();
            }

            UpdatePosition(false);
        }