DataGrid行拖拽需要我们自己去实现,我也是模仿网上例子进行改造。
大概思路,我们需要自定义一个DataGrid的控件,然后再样式中加入一个Popup(作为被拖拽行的显示),我们要弄成所有都可以使用,就需要将Popup内容显示的模板实现自动生成,我们可以在AutoGeneratingColumn事件里实现,我是使用XMAL的方式保存所有的控件,然后赋值给我们自定义的一个DataTemplate属性。
拖拽主要用到Drop、MouseLeftButtonDown事件。(需要将DataGird的AllowDrop设置为True)。
伪代码(自己自行去完整):
<Popup AllowsTransparency = "True" IsOpen = "{Binding IsPopup, RelativeSource = "{RelativeSource Mode = FindAncesTor, AncestorType = {x:Type xxxxxx}}}"
Foucusable = "False" IsHitestVisible = "False" Placement = "RelativePoint"
PlacementRectangle = "{Binding PopupPlacementRectangle, RelativeSource = "{RelativeSource Mode = FindAncesTor, AncestorType = {x:Type xxxxxx}}}" >
<Grid>