Last active
December 29, 2020 19:29
-
-
Save somapatrik/b2e1e2fd35c8ec5dd1751b52c9336606 to your computer and use it in GitHub Desktop.
Basic drag & drop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ------------------- 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