New bug? Dragsource moving over other Dragsources ghost

Nov 28, 2009 at 10:56 AM
Edited Nov 28, 2009 at 12:47 PM

Hi Kevin,

I am experiencing a weird behavior and I was hoping you could explain it. I'm not sure if its a bug... most likely something I don't understand.

For the most part I have been adding my drag sources and targets in xaml. However now I need to add them in behind code.

I add 2 drag sources( which are just images) to a wrappanel or a stack panel in behind code with ghosts ( same image with opacity changed).

Now when I drag out the dragsource on the left, the one on the right slides into the place of where the left one was and overlaps the ghost of the dragsource I just moved.

 

Here is my a sample of code.  

I am using the DragSourceContent and DragSourceGhost usercontrols from your sample. As you can see below. However I changed them so that I can bind my image and thats about all there is in there. See below

 

 

    WrapPanel wp= new WrapPanel();

DragSource dragSource1 = BuildDragSource("ford", "/Image/ford.png");
DragSource dragSource2 = BuildDragSource("toyota", "/Images/toy.png");
DragSource dragSource3 = BuildDragSource("Honda", "/Images/Honda.png");

wp.Children.Add(dragSource1);
wp.Children.Add(dragSource2);
wp.Children.Add(dragSource3);



private DragSource BuildDragSource(string tag, string imagename)
{
DragSource ds = new DragSource()
{
Content = new DragSourceContent() { DataContext = new myImage { Image = imagename } },
Ghost = new DragSourceGhost() { DataContext = new myImage { Image = imagename } },
ShowReturnToOriginalPositionAnimation = true,
};

ds.AllDropTargetsValid = true;
ds.DropMode = SL_Drag_Drop_BaseClasses.DragSource.DropModeType.ReturnDragSource;
ds.Tag = tag;
ds.ShowReturnToOriginalPositionAnimation = false;
ds.DragHandleMode = DragSource.DragHandleModeType.FullDragSource;

return ds;
}

 

DragSourceContent and DragSourceGhost

 

 

<UserControl x:Class="SL_Drag_Drop.DragSourceGhost"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="48" Height="48">
<Grid x:Name="LayoutRoot" Opacity="0.3">
<Image Source="{Binding Image}" />
</Grid>
</UserControl>




<UserControl x:Class="SL_Drag_Drop.DragSourceContent"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="48" Height="48">
<Grid x:Name="LayoutRoot">
<Image Source="{Binding Image}" />
</Grid>
</UserControl>


 

Any help at all is much appreciated.

 

UPDATE:  I noticed something different. If I say have 3 drag sources in a stackpanel and click on the one furthest to the left. I notice that it is moved to the furthest on the right of the three. so effectively if I keep on clicking on the one of the left they three are rotating through. 

Could this have something to do with the fact that my code is in the page constructor?

ANy help from anyone is much appreciated. This is driving me crazy!

cheers.

Nov 28, 2009 at 10:07 PM

Hey guys,

I worked out what I was doing wrong..... and thought I would post it.

Basically I was just adding a drag source to the page. not a drop target which contains a drag source.

 

Anyway all good now. I'm happy to elaborate if anyone has the same problem.

 

Once again thanks for the great control Kevin!