コード例 #1
0
        private static void VerifyRelativeContentPosition(Windows.Foundation.Point position, HorizontalPosition horizontalPosition, VerticalPosition verticalPosition, FrameworkElement content, double minimumTargetOffset, FrameworkElement target)
        {
            var contentScreenBounds = content.GetOnScreenBounds();
            var contentCenter       = contentScreenBounds.GetCenter();
            var targetScreenBounds  = target.GetOnScreenBounds();
            var targetCenter        = targetScreenBounds.GetCenter();
            var anchorPoint         = new Windows.Foundation.Point(targetScreenBounds.X + position.X, targetScreenBounds.Y + position.Y);

            Assert.IsTrue(targetCenter.X > minimumTargetOffset);
            Assert.IsTrue(targetCenter.Y > minimumTargetOffset);
            switch (horizontalPosition)
            {
            case HorizontalPosition.BeyondLeft:
                NumberAssert.GreaterOrEqual(anchorPoint.X, contentScreenBounds.Right);
                break;

            case HorizontalPosition.LeftFlush:
                Assert.AreEqual(anchorPoint.X, contentScreenBounds.Left, delta: 2);
                break;

            case HorizontalPosition.Center:
                Assert.AreEqual(anchorPoint.X, contentCenter.X, delta: 2);
                break;

            case HorizontalPosition.RightFlush:
                Assert.AreEqual(anchorPoint.X, contentScreenBounds.Right, delta: 2);
                break;

            case HorizontalPosition.BeyondRight:
                NumberAssert.LessOrEqual(anchorPoint.X, contentScreenBounds.Left);
                break;
            }

            switch (verticalPosition)
            {
            case VerticalPosition.BeyondTop:
                NumberAssert.GreaterOrEqual(anchorPoint.Y, contentScreenBounds.Bottom);
                break;

            case VerticalPosition.TopFlush:
                Assert.AreEqual(anchorPoint.Y, contentScreenBounds.Top, delta: 2);
                break;

            case VerticalPosition.Center:
                Assert.AreEqual(anchorPoint.Y, contentCenter.Y, delta: 2);
                break;

            case VerticalPosition.BottomFlush:
                Assert.AreEqual(anchorPoint.Y, contentScreenBounds.Bottom, delta: 2);
                break;

            case VerticalPosition.BeyondBottom:
                NumberAssert.LessOrEqual(anchorPoint.Y, contentScreenBounds.Top);
                break;
            }
        }
コード例 #2
0
        private static void VerifyRelativeContentPosition(Windows.Foundation.Point position, HorizontalPosition horizontalPosition, VerticalPosition verticalPosition, FrameworkElement content, double minimumTargetOffset, FrameworkElement target)
        {
            var contentScreenBounds = content.GetOnScreenBounds();

#if __ANDROID__
            if (FeatureConfiguration.Popup.UseNativePopup)
            {
                // Adjust for status bar height, which is omitted from TransformToVisual() for elements inside of a native popup.
                var rootViewBounds = ((FrameworkElement)Window.Current.Content).GetOnScreenBounds();
                contentScreenBounds.Y += rootViewBounds.Y;
            }
#endif
            var contentCenter      = contentScreenBounds.GetCenter();
            var targetScreenBounds = target.GetOnScreenBounds();
            var targetCenter       = targetScreenBounds.GetCenter();
            var anchorPoint        = new Windows.Foundation.Point(targetScreenBounds.X + position.X, targetScreenBounds.Y + position.Y);

            Assert.IsTrue(targetCenter.X > minimumTargetOffset);
            Assert.IsTrue(targetCenter.Y > minimumTargetOffset);
            switch (horizontalPosition)
            {
            case HorizontalPosition.BeyondLeft:
                NumberAssert.GreaterOrEqual(anchorPoint.X, contentScreenBounds.Right);
                break;

            case HorizontalPosition.LeftFlush:
                Assert.AreEqual(anchorPoint.X, contentScreenBounds.Left, delta: 2);
                break;

            case HorizontalPosition.Center:
                Assert.AreEqual(anchorPoint.X, contentCenter.X, delta: 2);
                break;

            case HorizontalPosition.RightFlush:
                Assert.AreEqual(anchorPoint.X, contentScreenBounds.Right, delta: 2);
                break;

            case HorizontalPosition.BeyondRight:
                NumberAssert.LessOrEqual(anchorPoint.X, contentScreenBounds.Left);
                break;
            }

            switch (verticalPosition)
            {
            case VerticalPosition.BeyondTop:
                NumberAssert.GreaterOrEqual(anchorPoint.Y, contentScreenBounds.Bottom);
                break;

            case VerticalPosition.TopFlush:
                Assert.AreEqual(anchorPoint.Y, contentScreenBounds.Top, delta: 2);
                break;

            case VerticalPosition.Center:
                Assert.AreEqual(anchorPoint.Y, contentCenter.Y, delta: 2);
                break;

            case VerticalPosition.BottomFlush:
                Assert.AreEqual(anchorPoint.Y, contentScreenBounds.Bottom, delta: 2);
                break;

            case VerticalPosition.BeyondBottom:
                NumberAssert.LessOrEqual(anchorPoint.Y, contentScreenBounds.Top);
                break;
            }
        }