简体   繁体   English

WPF 拖放到 DataGrid

[英]WPF drag and drop to DataGrid

I have been searching the internet high and low but can't find some examples that can help me.我一直在互联网上下搜索,但找不到一些可以帮助我的例子。

I'm developing an application in wpf, in it I use a DataGrid ;我正在 wpf 中开发一个应用程序,其中我使用了DataGrid each cell has a DataTemplate with and image, in a mosaic style;每个单元格都有一个带有和图像的DataTemplate ,采用马赛克样式; on the side of the grid I have some tiles to use on the grid.在网格的一侧,我有一些瓷砖可以在网格上使用。

I'm able to drag the tiles but can't drop them on the grid because I can't find the cell to which make the drop.我可以拖动图块但不能将它们放在网格上,因为我找不到放置的单元格。 Is there a way to get a cell position from the the drag events?有没有办法从拖动事件中获取单元格位置?

Thanks谢谢

I am assuming you suscribed to the drop event on the DataGrid.我假设您订阅了 DataGrid 上的 drop 事件。

Since you have a DataTemplate for each cell, you could subscribe to the drop event from the cell and you should be able to do the modification you want via e.Source.由于每个单元格都有一个 DataTemplate,因此您可以从单元格订阅 drop 事件,并且您应该能够通过 e.Source 进行所需的修改。

If you need to you could define a different DataTemplate for each column so that you can figure at the column and then modifiy the data via如果您需要,您可以为每列定义一个不同的 DataTemplate,以便您可以在列中进行计算,然后通过以下方式修改数据

BusinessObject row = ((UIElementResponsibleForTeDrop)e.Source).DataContext;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM