FlyoutArrow/FlyoutArrow/FlyoutArrowPresenter.cs
/// <summary>
/// Updates the points for drawing the polygon arrow
/// </summary>
Updates the points for drawing the polygon arrow
Updates the points for drawing the polygon arrow
private void UpdateArrowPoints()
        {
            if (FlyoutLocation != null && _content != null && _controlCanvas != null && _arrow != null)
            {
                var targetUiTransform = FlyoutLocation.TransformToVisual(_controlCanvas);
                var screenCoords = targetUiTransform.TransformPoint(new Point());
                var yDirection = -1;
                var yArrowBasePosition = _topPosition;
                if (screenCoords.Y >= 0)
                {
                    yDirection = 1;
                    yArrowBasePosition = _content.ActualHeight;
                }
                var yOffset = yDirection * 2;
                var halfFlyoutLocationWidth = FlyoutLocation.ActualWidth / 2.0;
                var halfArrowIndicatorWidth = ArrowIndicatorWidth / 2.0;
                var points = new PointCollection
                {
                    new Point(screenCoords.X - halfArrowIndicatorWidth + halfFlyoutLocationWidth, (yArrowBasePosition - yOffset)),
                    new Point(screenCoords.X + halfArrowIndicatorWidth + halfFlyoutLocationWidth, (yArrowBasePosition - yOffset)),
                    new Point(screenCoords.X + halfFlyoutLocationWidth, yArrowBasePosition + ArrowIndicatorHeight * yDirection)
                };
                _arrow.Points = points;
                var deltaX1 = (points[2].X - points[0].X);
                var deltaX2 = (points[2].X - points[1].X);
                var slope1 = (deltaX1 != 0.0) ? (points[2].Y - points[0].Y) / deltaX1 : 0;
                var slope2 = (deltaX2 != 0.0) ? (points[2].Y - points[1].Y) / deltaX2 : 0;
                _arrowOutlineLeft.X1 = points[2].X;
                _arrowOutlineLeft.Y1 = points[2].Y;
                _arrowOutlineLeft.X2 = (slope1 != 0.0) ? (yArrowBasePosition - points[2].Y) / slope1 + points[2].X : 0;
                _arrowOutlineLeft.Y2 = points[0].Y + yOffset;
                _arrowOutlineRight.X1 = points[2].X;
                _arrowOutlineRight.Y1 = points[2].Y;
                _arrowOutlineRight.X2 = (slope1 != 0.0) ? (yArrowBasePosition - points[2].Y) / slope2 + points[2].X : 0;
                _arrowOutlineRight.Y2 = points[1].Y + yOffset;
            }
        }
private void UpdateArrowPoints ( ) { if ( FlyoutLocation != null && _content != null && _controlCanvas != null && _arrow != null ) { var targetUiTransform = FlyoutLocation . TransformToVisual ( _controlCanvas ) ; var screenCoords = targetUiTransform . TransformPoint ( new Point ( ) ) ; var yDirection = - 1 ; var yArrowBasePosition = _topPosition ; if ( screenCoords . Y >= 0 ) { yDirection = 1 ; yArrowBasePosition = _content . ActualHeight ; } var yOffset = yDirection * 2 ; var halfFlyoutLocationWidth = FlyoutLocation . ActualWidth / 2.0 ; var halfArrowIndicatorWidth = ArrowIndicatorWidth / 2.0 ; var points = new PointCollection { new Point ( screenCoords . X - halfArrowIndicatorWidth + halfFlyoutLocationWidth , ( yArrowBasePosition - yOffset ) ) , new Point ( screenCoords . X + halfArrowIndicatorWidth + halfFlyoutLocationWidth , ( yArrowBasePosition - yOffset ) ) , new Point ( screenCoords . X + halfFlyoutLocationWidth , yArrowBasePosition + ArrowIndicatorHeight * yDirection ) } ; _arrow . Points = points ; var deltaX1 = ( points [ 2 ] . X - points [ 0 ] . X ) ; var deltaX2 = ( points [ 2 ] . X - points [ 1 ] . X ) ; var slope1 = ( deltaX1 != 0.0 ) ? ( points [ 2 ] . Y - points [ 0 ] . Y ) / deltaX1 : 0 ; var slope2 = ( deltaX2 != 0.0 ) ? ( points [ 2 ] . Y - points [ 1 ] . Y ) / deltaX2 : 0 ; _arrowOutlineLeft . X1 = points [ 2 ] . X ; _arrowOutlineLeft . Y1 = points [ 2 ] . Y ; _arrowOutlineLeft . X2 = ( slope1 != 0.0 ) ? ( yArrowBasePosition - points [ 2 ] . Y ) / slope1 + points [ 2 ] . X : 0 ; _arrowOutlineLeft . Y2 = points [ 0 ] . Y + yOffset ; _arrowOutlineRight . X1 = points [ 2 ] . X ; _arrowOutlineRight . Y1 = points [ 2 ] . Y ; _arrowOutlineRight . X2 = ( slope1 != 0.0 ) ? ( yArrowBasePosition - points [ 2 ] . Y ) / slope2 + points [ 2 ] . X : 0 ; _arrowOutlineRight . Y2 = points [ 1 ] . Y + yOffset ; } }
Updates the points for drawing the polygon arrow
Updates the points for drawing the polygon arrow
// Get the coordinates of the canvas relative to the flyout location // Determine the x, y location of the arrow // and the direction the arrow points towards to. // yDirection of -1 indicates the direction of the arrow is drawn upwards // yDirection of 1 indicates the direction of the arrow is drawn downwards // If the arrow is at the top, the base of the arrow aligns with the top // edge of the flyout content. // If the arrow is at the bottom, the base of the arrow aligns with the // bottom edge of the flyout content. // The math here is to calculate the point from the tip of the arrow to the base of the // popup box. We do this because the actual triangle beak's base is slighting offset into the // popup box to cover the outline of the popup box. The goal is to get the ouline around // the popup box and triangle as one item.