예제 #1
0
        private double CalculateYOffset(FrameworkElement itemToAnimate)
        {
            FrameworkElement rootElement  = this.containerToAnimate; // TODO - get the root
            Point            globalCoords = ElementTreeHelper.SafeTransformPoint(itemToAnimate, rootElement, new Point());

            double heightAdjustment = itemToAnimate.ActualHeight / 2;
            double yCoord           = globalCoords.Y + heightAdjustment;

            return((rootElement.ActualHeight / 2) - yCoord);
        }
예제 #2
0
        private bool IsItemVisible(FrameworkElement itemToAdd)
        {
            if (itemToAdd == null || itemToAdd.Visibility == Visibility.Collapsed)
            {
                return(false);
            }

            Size renderSize = itemToAdd.RenderSize;

            if (renderSize.Width == 0 || renderSize.Height == 0)
            {
                return(false);
            }

            FrameworkElement rootVisual = Window.Current.Content as FrameworkElement;

            Point globalPosition = ElementTreeHelper.SafeTransformPoint(itemToAdd, rootVisual, new Point());

            double itemWidth  = itemToAdd.Width;
            double itemHeight = itemToAdd.Height;

            if ((globalPosition.X + itemWidth) < 0 ||
                (globalPosition.Y + itemHeight) < 0 ||
                globalPosition.X > rootVisual.ActualWidth ||
                globalPosition.Y > rootVisual.ActualHeight)
            {
                return(false);
            }

            ScrollViewer parentScrollViewer = ElementTreeHelper.FindVisualAncestor <ScrollViewer>(itemToAdd);

            if (parentScrollViewer != null)
            {
                Point localPosition = ElementTreeHelper.SafeTransformPoint(itemToAdd, parentScrollViewer, new Point());
                if ((localPosition.X + itemWidth) < 0 ||
                    (localPosition.Y + itemHeight) < 0 ||
                    localPosition.X > parentScrollViewer.ActualWidth ||
                    localPosition.Y > parentScrollViewer.ActualHeight)
                {
                    return(false);
                }
            }

            return(true);
        }