使用InputSimulator将鼠标拖动到目标

时间:2016-12-15 00:17:50

标签: c# wpf coded-ui-tests

我需要拖动一个WPF元素并插入另一个WPF目标元素。我一直在测试代码中使用InputSimulator进行所有键盘交互。但是没有找到任何关于用InputSimulator拖动鼠标的东西。对此有何见解?

1 个答案:

答案 0 :(得分:0)

您可以使用Mouse Class中的本机编码ui方法。像,

根据OP请求编辑:

// Determine drop coordinates dynamically       
Point dropDestinationPoint = controlYouWanttoDropOn.GetClickablePoint();
// Add some buffer to avoid possible clicking over the edges - Optional
dropDestinationPoint.X += 5; 
dropDestinationPoint.Y += 5;    
Mouse.StartDragging(controlYouWantToDrag);
Mouse.StopDragging(controlYouWanttoDropOn, dropDestinationPoint);

您也可以尝试通过BoundingRectangle属性获取点数并使用它。