Drag WPF Popup control

前端 未结 6 1061
死守一世寂寞
死守一世寂寞 2020-12-13 14:32

the WPF Popup control is nice, but somewhat limited in my opinion. is there a way to \"drag\" a popup around when it is opened (like with the DragMove() method of windows)?<

6条回答
  •  眼角桃花
    2020-12-13 15:31

    Private Point startPoint;
    
     private void Window_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
    
            startPoint = e.GetPosition(null);
        }
    private void Window_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                Point relative = e.GetPosition(null);
                Point AbsolutePos = new Point(relative.X + this.Left, relative.Y + this.Top);
                this.Top = AbsolutePos.Y - startPoint.Y;
                this.Left = AbsolutePos.X - startPoint.X;
            }
        }
    

    This works for dragging my window, but like it was told if i move the mouse to fast, it would get out of window and stop raising the event. Without mentioning the dragging is not smooth at all. Does anyone knows how to do it properly, nice and smooth dragging, without loosing it when dragged too fast??? Post a simple example if possible, other than a whole tutorial that would get beginners like me lost in code. Thanks!

提交回复
热议问题