Ejemplo n.º 1
0
        private Point GetAnchorOffset(AnchorBorder anchorBorder, FrameworkElement placementTarget, Point topLeftToTargetPoint, Point topRightToTargetPoint, bool isAbove)
        {
            if (anchorBorder == null || placementTarget == null)
            {
                throw new ArgumentNullException(anchorBorder == null ? "anchorBorder" : "placementTarget");
            }

            var anchorPoint = new Point();

            if (topRightToTargetPoint.X <= 0)
            {
                anchorPoint.X = 0;
                anchorPoint.Y = isAbove ? 0 : placementTarget.ActualHeight;
            }

            if (topLeftToTargetPoint.X <= 0 && topRightToTargetPoint.X > 0)
            {
                anchorPoint.X = Math.Min(topRightToTargetPoint.X, placementTarget.ActualWidth) / 2;
                anchorPoint.Y = isAbove ? 0 : placementTarget.ActualHeight;
            }

            if (topLeftToTargetPoint.X > 0)
            {
                anchorPoint.X = Math.Min((placementTarget.ActualWidth - topLeftToTargetPoint.X) / 2 + topLeftToTargetPoint.X, placementTarget.ActualWidth);
                anchorPoint.Y = isAbove ? 0 : placementTarget.ActualHeight;
            }

            return(new Point(anchorPoint.X - topLeftToTargetPoint.X + (isAbove ? anchorBorder.CornerRadius.TopLeft : anchorBorder.CornerRadius.BottomLeft), isAbove ? Math.Abs(anchorBorder.AnchorOffset.Y) : (anchorPoint.Y - topLeftToTargetPoint.Y - Math.Abs(anchorBorder.AnchorOffset.Y))));
        }
Ejemplo n.º 2
0
        private double GetDockOffset(AnchorBorder anchorBorder, FrameworkElement placementTarget, Point topLeftToTargetPoint, Point topRightToTargetPoint, bool isAbove)
        {
            if (anchorBorder == null || placementTarget == null)
            {
                throw new ArgumentNullException(anchorBorder == null ? "anchorBorder" : "placementTarget");
            }

            double leftDockOffset = 0;

            if (topRightToTargetPoint.X <= anchorBorder.DockLength)
            {
                leftDockOffset = topRightToTargetPoint.X - topLeftToTargetPoint.X - anchorBorder.DockLength + (isAbove ? anchorBorder.CornerRadius.TopLeft : anchorBorder.CornerRadius.BottomLeft);
            }

            if (topRightToTargetPoint.X > anchorBorder.DockLength && topLeftToTargetPoint.X <= placementTarget.ActualWidth - anchorBorder.DockLength)
            {
                leftDockOffset = anchorBorder.AnchorOffset.X - (anchorBorder.DockLength / 2);
            }

            if (topLeftToTargetPoint.X > (placementTarget.ActualWidth - anchorBorder.DockLength))
            {
                leftDockOffset = (isAbove ? anchorBorder.CornerRadius.TopLeft : anchorBorder.CornerRadius.BottomLeft);
            }

            return(leftDockOffset);
        }
Ejemplo n.º 3
0
        private void Construct()
        {
            _contentPresenter = new ContentPresenter();
            _anchorBorder     = ConstructAnchorBorder();
            _grid             = new Grid();
            _popup            = ConstructPopup();

            _anchorBorder.Child = _contentPresenter;
            _grid.Children.Add(_anchorBorder);

            _popup.Child = _grid;
        }
Ejemplo n.º 4
0
        private double GetDockOffset(AnchorBorder anchorBorder, FrameworkElement placementTarget, Point topLeftToTargetPoint, Point leftRightToTargetPoint, bool isAbove)
        {
            if (anchorBorder == null || placementTarget == null)
            {
                throw new ArgumentNullException(anchorBorder == null ? "anchorBorder" : "placementTarget");
            }

            if (DoubleUtil.GreaterThanOrClose(topLeftToTargetPoint.X, 0))
            {
                return(Math.Max(
                           _cornerRadius,
                           Math.Min(placementTarget.ActualWidth - topLeftToTargetPoint.X, anchorBorder.ActualWidth) / 2 - anchorBorder.DockLength / 2));
            }

            if (DoubleUtil.GreaterThanOrClose(anchorBorder.ActualWidth + topLeftToTargetPoint.X, 2 * _cornerRadius + anchorBorder.DockLength))
            {
                return(Math.Max(
                           _cornerRadius,
                           (anchorBorder.ActualWidth + topLeftToTargetPoint.X) / 2 - anchorBorder.DockLength + Math.Abs(topLeftToTargetPoint.X)));
            }

            return(anchorBorder.ActualWidth - _cornerRadius - anchorBorder.DockLength);
        }
Ejemplo n.º 5
0
        private Point GetAnchorOffset(AnchorBorder anchorBorder, FrameworkElement placementTarget, Point topLeftToTargetPoint, Point leftRightToTargetPoint, bool isAbove)
        {
            if (anchorBorder == null || placementTarget == null)
            {
                throw new ArgumentNullException(anchorBorder == null ? "anchorBorder" : "placementTarget");
            }

            var anchorYOffset = isAbove ? Math.Abs(anchorBorder.AnchorOffset.Y) : -Math.Abs(anchorBorder.AnchorOffset.Y);

            if (DoubleUtil.GreaterThanOrClose(topLeftToTargetPoint.X, 0))
            {
                var validWidth    = Math.Min(placementTarget.ActualWidth - topLeftToTargetPoint.X, anchorBorder.ActualWidth) / 2;
                var anchorXOffset = Math.Min(validWidth, anchorBorder.DockOffset + anchorBorder.DockLength / 2);

                return(new Point(anchorXOffset, anchorYOffset));
            }

            if (DoubleUtil.GreaterThanOrClose(anchorBorder.ActualWidth + topLeftToTargetPoint.X, 2 * _cornerRadius + anchorBorder.DockLength))
            {
                return(new Point(anchorBorder.DockOffset + anchorBorder.DockLength / 2, anchorYOffset));
            }

            return(new Point(Math.Abs(topLeftToTargetPoint.X), anchorYOffset));
        }