我有一个应用程序,将从DevExpress网格拖到DevExpress树视图。网格中的DragDropEffects为“复制”并且不移动。用户还可以在TreeView中拖放。我有一个链接到两个控件的MouseMove事件。我必须将其与Grid关联,因为我需要复制对象而不是移动对象。我遇到的问题是,如果我双击一行然后尝试将其拖放,则会收到错误消息“分派器处理已暂停,但消息仍在处理中”。我知道从网格中删除MouseMove事件可以修复该错误,但随后它会移动该项目并且不会将其复制。我希望能够以某种方式告诉XAML中的Grid始终将复制与拖放结合使用。有没有办法解决这个问题?
C#代码:
public void MouseMove(object Source, MouseEventArgs E)
{
try
{
if (E.LeftButton == MouseButtonState.Pressed)
{
DragDropEffects ddp = DragDropEffects.Move;
if (SelectedItem != null)
{
ddp = DragDropEffects.Move;
}
else if (SelectedChoice != null)
{
ddp = DragDropEffects.Copy;
}
DragDrop.DoDragDrop(E.Source as DependencyObject, SelectedItem == null ? SelectedChoice : SelectedItem, ddp);
}
}
catch (System.InvalidOperationException exo)
{
'Dispatcher processing has been suspended, but messages are still being processed.'
}
catch (Exception ex)
{
MessageBox.Show("Error in MouseMove: " + ex.Message);
}
}
XAML:
<dxg:GridControl x:Name="AvailableChoicesGrid" SelectionMode="Row" Style="{StaticResource ChoicesGridControl}" ItemsSource="{Binding AvailableChoices}" SelectedItem="{Binding SelectedChoice, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseMove">
<ei:CallMethodAction MethodName="MouseMove" TargetObject="{Binding}"/>
</i:EventTrigger>
<i:EventTrigger EventName="Drop">
<ei:CallMethodAction MethodName="DropTarget" TargetObject="{Binding}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<dxg:GridControl.View>
<dxg:TableView Style="{StaticResource AvailableChoicesTable}" AllowDragDrop="True" />
</dxg:GridControl.View>
</dxg:GridControl>