Skip to content

Instantly share code, notes, and snippets.

@somapatrik
Last active December 29, 2020 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save somapatrik/b2e1e2fd35c8ec5dd1751b52c9336606 to your computer and use it in GitHub Desktop.
Save somapatrik/b2e1e2fd35c8ec5dd1751b52c9336606 to your computer and use it in GitHub Desktop.
Basic drag & drop
// ------------------- Drag side -----------------------
// -----------------------------------------------------
Point StartPosition;
private void PLC_PreviewMouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
Point mousePos = e.GetPosition(null);
Vector diff = StartPosition - mousePos;
if (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
{
PlcButton butt = (PlcButton)sender;
DataObject dragData = new DataObject("DragPlcFormat", butt.s7plc);
DragDrop.DoDragDrop(this, dragData, DragDropEffects.Move);
Refresh();
}
}
}
private void PLC_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
StartPosition = e.GetPosition(null);
}
// ------------------- Drop side -----------------------
// -------- Must allow drop inside control XAML --------
private void UserControl_DragEnter(object sender, DragEventArgs e)
{
if (!e.Data.GetDataPresent("DragPlcFormat"))
{
//
}
}
private void UserControl_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent("DragPlcFormat"))
{
S7PLC draged = (S7PLC)e.Data.GetData("DragPlcFormat");
draged.UpdateGroup(ID_GROUP);
Refresh();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment