I have a mainWindow within a grid and a couple of wpf UserControls inside this grid.
I have as well three methods that control the movement inside the grid through my mouse.
MouseDown
, MouseMove
and MouseUp
and it works properly.
When I add a WindowsFormsHost
inside one of these UserControl, it just DOESN'T work anymore. I can move the window, but the WindowsFormsHost
stays in the same place.
I'd like to know how to move a window inside a grid using mouse events when I have a WindowsFormsHost
inside.
Thanks in advance.
Regards, Felipe.
PS. These are the methods I use to move my UserControl inside the grid.
public void Control_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
isDragging = true;
var draggableControl = sender as UserControl;
clickPosition = e.GetPosition(this);
draggableControl.CaptureMouse();
}
public void Control_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
isDragging = false;
var draggable = sender as UserControl;
draggable.ReleaseMouseCapture();
}
public void Control_MouseMove(object sender, MouseEventArgs e)
{
var draggableControl = sender as UserControl;
if (isDragging && draggableControl != null)
{
Point currentPosition = e.GetPosition(this.Parent as UIElement);
var transform = draggableControl.RenderTransform as TranslateTransform;
if (transform == null)
{
transform = new TranslateTransform();
draggableControl.RenderTransform = transform;
}
transform.X = currentPosition.X - clickPosition.X;
transform.Y = currentPosition.Y - clickPosition.Y;
}
}