Search code examples
c#wpfwindowswindows-8modern-ui

Get item's object for the dropped gridview Grid


I have a GridView with a custom template. I want the user to be able to drop some of items on another items. I enabled the drag & drop and added the drop handler to the Grid which is used for item's template:

        <GridView.ItemTemplate>
            <DataTemplate>
                <Grid HorizontalAlignment="Left" Width="250" Height="250" AllowDrop="True" Drop="content_Drop">

With the code above, I'm able to handle which Grid the user has dropped the item onto. However, I'm not able to get the object for this Grid. A trick (using an invisible control and lookup) comes to my mind but I'm looking for a better way.


Solution

  • The DataContext property of the Grid will be set to the item bound to that ItemTemplate.