Reputation: 11
i have three panels which holds three different user controls namely A, B and C.(note: these user controls are generated at runtime). the drag and drop from A to B and B to C forms a valid string in my application.
consider, A1, A2, A3 and A4 as instances of control A. and B1, B2, B3 and B4 as instances of control B and C1 and C2 as instances of control C.
consider, A1 is dragged and dropped on B1. which can then be dropped on C1 or C2. i want to restrict drag and drop behaviour of control B*(i mean, if i drop on B1 then i should be able to drag only B1 and not other instances).* currently, i can drag any instance irrespective of drop.
could any one give me some idea to achive the same?
Upvotes: 0
Views: 2359
Reputation: 5462
Here is the sample project that i have created uses three different controls and you can drag and drop in any of them and if you want to learn more you can visit WPFTutorial here int the sample project you can set drop target where ever you want to allow drop and if not you can set it to false.
Upvotes: 1
Reputation: 1279
Add a property to your type "B" control that indicates it is available for future Drag and Drop operations.
private bool IsActiveDragSource { get; set; }
Add a handler to the "Drop" event of your type 'B' control which sets the "IsActiveDragSource" property to true
private void label_Drop(object sender, DragEventArgs e)
{
// Handle the drop from control A
this.IsActiveDragSource = true;
}
In your MouseMove (or whatever Drag Source event you have chosen) only instantiate the DoDragDrop operation if your new property is set to true.
private void control_MouseMove(object sender, MouseEventArgs e)
{
if (this.IsActiveDragSource)
{
// Initialize the drag drop operation
DragDrop.DoDragDrop(this, this, DragDropEffects.Copy);
}
}
Upvotes: 0