GetDropTargetAdvisor returns wrong item?

Jan 27, 2009 at 2:31 AM
Edited Jan 27, 2009 at 2:33 AM
I have a simple DataTemplate that I use in a ListBox. I want each item in the ListBox to have a DropTargetAdvisor so I can drop an item into it. I have set break points, and in the following function if I use Mole, I can see that depObj is the correct ListItem. However, the IDropTargetAdvisor.TargetUI that returns ALWAYS is the the last item in the list. I've also stepped through the code and confirmed that an advisor is attached for each item Am I missing something?

public

 

static IDropTargetAdvisor GetDropTargetAdvisor(DependencyObject depObj)
{
       return depObj.GetValue(DropTargetAdvisorProperty) as IDropTargetAdvisor;
}

 

 

 

 

<DataTemplate x:Key="ModuleItemView">
    <Grid Width="64" Height="64" fk:DragDropManager.DropTargetAdvisor="{StaticResource DropTargetAdvisor}">
        <Grid.Background>
            <LinearGradientBrush EndPoint="0.5,-1.228" StartPoint="0.5,1">
               <GradientStop Color="#99000000" Offset="0"/>
               <GradientStop Color="#FFFFFFFF" Offset="1"/>
           </LinearGradientBrush>
      </Grid.Background>
      <Image Source="{Binding Path=Icon, Converter={StaticResource ImagePathConverter}, ConverterParameter='64', UpdateSourceTrigger=PropertyChanged}"/>
   </Grid>
</DataTemplate>

 

 

 

 

 

 

 

Jan 27, 2009 at 3:22 AM
Edited Jan 27, 2009 at 3:24 AM
I made the following change to the DragDropManager, and it resolved the issue. However, I would like to hear your thoughts on this as I'm not entirely convinced this is the correct approach.

 private static void DropTarget_PreviewDragEnter(object sender, DragEventArgs e)

if 

 

(CurrentDropTargetAdvisor.TargetUI != sender as UIElement)
    CurrentDropTargetAdvisor.TargetUI = sender
as UIElement;