XAML
1
2
3
4
5
6
7
8
9
10
|
<ListBox ItemTemplate="{StaticResource HandBrandShowTemplate}"
ItemsSource="{Binding showHandBrands,
Mode=TwoWay,
IsAsync=True}"
SelectedItem="{Binding selectedHandBrand,
Mode=TwoWay}"
x:Name="handBrandListbox"
dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True"
dd:DragDrop.DropHandler="{Binding}">
|
ViewModel
implement interface IDropTarget
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
public void DragOver(IDropInfo dropInfo)
{
HandBrandItemViewModel sourceItem = dropInfo.Data as HandBrandItemViewModel;
HandBrandItemViewModel targetItem = dropInfo.TargetItem as HandBrandItemViewModel;
if (sourceItem != null && targetItem != null && targetItem.CanAcceptChildren)
{
dropInfo.DropTargetAdorner = DropTargetAdorners.Highlight;
dropInfo.Effects = DragDropEffects.Copy;
}
}
public void Drop(IDropInfo dropInfo)
{
HandBrandItemViewModel sourceItem = dropInfo.Data as HandBrandItemViewModel;
HandBrandItemViewModel targetItem = dropInfo.TargetItem as HandBrandItemViewModel;
targetItem.Children.Add(sourceItem);
var msg = new HostMessage("正在进行房间拖拽操作...."
+ "\n 源手牌号:" + sourceItem.handBrand.handBrandShowId
+ "\n 目标手牌号:" + targetItem.handBrand.handBrandShowId
, "HandBrandDialog");
}
|