Search code examples
wpfdrag-and-dropitemscontrol

WPF: Can't drop dragged data onto an ItemsControl


I have the following XAML:

<DockPanel x:Name="OverViewContainer" AllowDrop="True">
    <StackPanel Orientation="Horizontal"
                DockPanel.Dock="Bottom"
                HorizontalAlignment="Right">
        <uicommon:Toolbar DataContext="{Binding Commands}" />
    </StackPanel>
    <ItemsControl ItemsSource="{Binding DocumentElements}"
                  ItemTemplate="{DynamicResource DocumentElementsItemTemplate}" />
</DockPanel>

When I drag data onto this panel, the mouse cursor shows a drop is allowed on all the child items, but on any empty space, the cursor shows that dropping is disabled. If I set AllowDrop to false, I can't drop onto the child items anymore, so the flag DOES have an effect. I would like to drop data into the margins between the items in the ItemsControl.

Any ideas?


Solution

  • The problem is that your DockPanel is not performing hit testing - since it has no background.

    The solution? Add a Background="Transparent" attribute to the <DockPanel> tag.