Search code examples
c#wpfxamlwindows-store-appsuwp

Why does this drag drop not work?


I am currently developing a Universal Windows Phone application, where I want a drag and drop functionality from a ListView to a Canvas.

Now I have this XAML code:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <ListView DragItemsStarting="ListView_DragItemsStarting" CanDragItems="True">
        <Image Source="../../Assets/Images/Logo.png"/>
    </ListView>

    <ListView 
        Grid.Column="1"
        AllowDrop="True"
        Drop="Canvas_Drop"/>
</Grid>

This code works, but the moment I change the second ListView into a Canvas, the drop event handler no longer gets called.

Any ideas why and how I can solve this?


Solution

  • Set the background to Transparent and it should work.

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <ListView DragItemsStarting="ListView_DragItemsStarting" CanDragItems="True">
            <Image Source="../../Assets/Images/Logo.png"/>
        </ListView>
    
        <ListView 
            Grid.Column="1"
            AllowDrop="True"
            Drop="Canvas_Drop"
            Background="Transparent"/>
    </Grid>