Esempio n. 1
0
        /// <summary>
        /// 弹出
        /// </summary>
        /// <param name="popupItem">窗体实例</param>
        /// <param name="rect">矩形区域</param>
        /// <returns>Task</returns>
        private async Task ShowPopup(PopupItem popupItem, Rectangle rect)
        {
            //重绘
            _rect = rect;
            _canvasView.InvalidateSurface();

            // 响应不传递
            _absoluteLayout.InputTransparent = false;

            // 画布可见
            _canvasView.IsVisible = true;

            // 获取弹窗的view对象
            var popup = ((AbsoluteLayout)Children[1]).Children.First(c => c == popupItem.Content);

            // 向内偏移2
            var localRect = new Rectangle(rect.X + 2, rect.Y + 2, rect.Width - 4, rect.Height - 4);

            // 设置弹窗位置
            popup.SetValue(AbsoluteLayout.LayoutBoundsProperty, localRect);

            // 弹窗对象可见
            //popupItem.IsShown = true;

            // 弹窗view可见
            popup.IsVisible = true;

            // 显示动画
            await Task.WhenAll(
                popup.FadeTo(1, 200, Easing.CubicInOut),
                _canvasView.FadeTo(1, 200, Easing.CubicInOut)
                ).ConfigureAwait(false);
        }
Esempio n. 2
0
        public async Task PopUpOverBelow(object visualElement, PopupItem popupItem, float width, float height)
        {
            _absoluteLayout.InputTransparent = false;

            var popup = ((AbsoluteLayout)Children[1]).Children.First(c => c == popupItem.Content);

            var v     = visualElement as VisualElement;
            var x     = v.X;
            var y     = v.Y;
            var w     = v.Width;
            var h     = v.Height;
            var ifPop = false;

            while (true)
            {
                v = v.Parent as VisualElement;
                if (v != null)
                {
                    x += v.X;
                    y += v.Y;
                    if (v == this)
                    {
                        ifPop = true;
                        break;
                    }
                }
                else
                {
                    break;
                }
            }

            if (ifPop)
            {
                popup.SetValue(AbsoluteLayout.LayoutBoundsProperty, new Rectangle(x, y + h, width, height));

                //popupItem.IsShown = true;

                popup.IsVisible = true;

                await Task.WhenAll(
                    popup.FadeTo(1, 200, Easing.CubicInOut)
                    );
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 弹出
        /// </summary>
        /// <param name="popupItem">窗体实例</param>
        /// <param name="clickElem">被点击元素</param>
        /// <param name="width">弹窗宽度</param>
        /// <param name="height">弹窗高度</param>
        /// <returns></returns>
        public async Task ShowPopup(PopupItem popupItem, VisualElement clickElem, double width = 100, double height = 200, bool isProportional = false, bool isDrawTriangle = false)
        {
            if (isProportional)
            {
                width  = width > 1 ? 1 : width;
                height = height > 1 ? 1 : height;
            }

            _isDrawTriangle = isDrawTriangle;

            // 获取点击元素相对X
            var x = clickElem.X;
            // 获取点击元素相对Y
            var y = clickElem.Y;
            // 获取点击元素高
            var h = clickElem.Height;

            // 获取点击元素父元素
            var parent = clickElem.Parent as VisualElement;

            // 如果父元素不是this布局对象
            while (parent != this)
            {
                // X加上父元素的相对偏移量
                x += parent.X;
                // Y加上父元素的相对偏移量
                y += parent.Y;
                // 获取父元素的父元素
                parent = parent.Parent as VisualElement;
            }


            _drawX = x;

            // 加上元素高度后为弹窗起始y
            if (Children[0].GetType() == typeof(ScrollView))
            {
                var scrollView = Children[0] as ScrollView;
                var scrollY    = scrollView.ScrollY;
                y = y + h - scrollY;
            }
            else
            {
                y = y + h;
            }

            if (isProportional)
            {
                width = Width * width;

                if ((y - h / 2) < (Height / 2))
                {
                    height = (Height - y) * height;
                }
                else
                {
                    height = (y - h) * height;
                }
            }

            // 弹窗宽度大于屏幕宽度
            if (width > Width)
            {
                // 起始x位置设置为0
                x = 0;
                // 宽度设置为屏幕宽度
                width = Width;
            }
            else
            {
                // 如果x加上弹窗宽度超出屏幕
                if (x + width > Width)
                {
                    x = Width - width;
                }
            }

            //var test = absoluteLayout.Height;
            // 点击元素位置在屏幕位置一半以上
            if ((y - h / 2) < (Height / 2))
            {
                // 弹窗高度大于下方剩余屏幕高度
                if (height > Height - y)
                {
                    height = Height - y;
                }

                // 箭头向上
                _isArrowUp = true;
            }
            else
            {
                // 弹窗高度大于上方剩余屏幕高度
                if (height > y - h)
                {
                    height = y - h;
                }
                // 设置y起始位置为点击元素起始位置往上height高度处
                y = y - h - height;

                // 箭头向下
                _isArrowUp = false;
            }

            // 当获取到绝对X、Y后,弹窗
            await ShowPopup(popupItem, new Rectangle(x, y, width, height));
        }