个人资料

跳过导航链接首页 > 博客列表 > 博客正文

UWP应用内自定义弹出窗口

分类:

可拖动,可resize

如下图所示:

拖动参考:

https://www.songshizhao.com/blog/blogPage/1440.html

resize代码参考:


            Window.Current.CoreWindow.PointerMoved += (s, e) =>
            {

                try
                {
                    Windows.UI.Input.PointerPoint p = e.CurrentPoint;
                    if (sizeable_mark.IsPressed || can_resize)
                    {

                        if (p.Properties.IsLeftButtonPressed)
                        {


                            can_resize = true;

                            //获得移动距离
                            double deltaX = p.Position.X - _oldPosition2.X;
                            double deltaY = p.Position.Y - _oldPosition2.Y;


                            double nw = ChildWidth + deltaX;
                            var nh= ChildHeight + deltaY;
                            if (nw < 100) nw = 100;
                            if (nh < 45) nh = 100;
                            //ChildWidth += deltaX;
                            //ChildHeight += deltaY;
                            ChildWidth = nw;
                            ChildHeight = nh;


                        }
                        else
                        {
                            //鼠标按键没有按下 则禁止resize
                            can_resize = false;
 
                        }

                    }

                    //调整基准位置
                    //can_resize = false;
                    _oldPosition2 = new Point(p.Position.X, p.Position.Y);
                }
                catch (Exception ex)
                {

                    Debug.WriteLine(ex.Message+ex.Source.ToString());
                }

              

            };


      private double childWidth=400;

        public double ChildWidth
        {
            get { return childWidth; }
            set {

                //if (value<20)
                //{
                //    value = 20;
                //}
                childWidth = value; 
                
                OnPropertyChanged();
            
            }
        }

        private double childHeight=300;

        public double ChildHeight
        {
            get { return childHeight; }
            set { childHeight = value;

                //if (value < 20)
                //{
                //    value = 20;
                //}

                OnPropertyChanged(); }
        }

        private Point _oldPosition;
        private Point _oldPosition2;
        public bool can_resize { get; set; } = false;




songshizhao
最初发表2021/11/12 23:24:09 最近更新2021/11/12 23:33:39 11
为此篇作品打分
10
   评论