This project is read-only.

GetDropTargetAdvisor returns wrong item?

Jan 27, 2009 at 3:31 AM
Edited Jan 27, 2009 at 3: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?



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}">
            <LinearGradientBrush EndPoint="0.5,-1.228" StartPoint="0.5,1">
               <GradientStop Color="#99000000" Offset="0"/>
               <GradientStop Color="#FFFFFFFF" Offset="1"/>
      <Image Source="{Binding Path=Icon, Converter={StaticResource ImagePathConverter}, ConverterParameter='64', UpdateSourceTrigger=PropertyChanged}"/>








Jan 27, 2009 at 4:22 AM
Edited Jan 27, 2009 at 4: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)



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