code_junkie

Drag WPF Popup control

Nov 11th, 2011
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. <Popup x:Name="pop" IsOpen="True" Height="200" Placement="AbsolutePoint" Width="200">
  2. <Rectangle Stretch="Fill" Fill="Red"/>
  3. </Popup>
  4.  
  5. pop.MouseMove += new MouseEventHandler(pop_MouseMove);
  6.  
  7. void pop_MouseMove(object sender, MouseEventArgs e)
  8. {
  9. if (e.LeftButton == MouseButtonState.Pressed)
  10. {
  11. pop.PlacementRectangle = new Rect(new Point(e.GetPosition(this).X,
  12. e.GetPosition(this).Y),new Point(200,200));
  13.  
  14. }
  15. }
  16.  
  17. Private Point startPoint;
  18.  
  19. private void Window_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  20. {
  21.  
  22. startPoint = e.GetPosition(null);
  23. }
  24. private void Window_MouseMove(object sender, MouseEventArgs e)
  25. {
  26. if (e.LeftButton == MouseButtonState.Pressed)
  27. {
  28. Point relative = e.GetPosition(null);
  29. Point AbsolutePos = new Point(relative.X + this.Left, relative.Y + this.Top);
  30. this.Top = AbsolutePos.Y - startPoint.Y;
  31. this.Left = AbsolutePos.X - startPoint.X;
  32. }
  33. }
Add Comment
Please, Sign In to add comment