大佬教程收集整理的这篇文章主要介绍了PointerReleased 不在 UWP 控制之外工作,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个可以在控件内移动的绘制对象。
Pointerpressed、PointerMoved 和 PointerReleased 事件捕获鼠标在控件内的移动。
虽然一旦我将光标移到控件之外,事件就不再被触发。这与 WinForms 的行为不同,这是我所习惯的。
当鼠标可能在控件和/或窗口之外时,我需要一种方法来保持在控件内移动对象。
我不敢相信我没有发现任何人像我一样沮丧,试图找到一个简单的答案。我不相信微软不会想到这一点并提出了一个直接的解决方案:(
这是我迄今为止尝试过的:
private Point _prevIoUsDraggingPoint;
private bool _isMovingImage;
private voID canvas_Pointerpressed(object sender,PointerRoutedEventArgs E)
{
_prevIoUsDraggingPoint = e.GetCurrentPoint(sender as UIElement).position;
_isMovingImage = true;
}
private voID canvas_PointerReleased(object sender,PointerRoutedEventArgs E)
{
_isMovingImage = false;
}
private voID canvas_PointerMoved(object sender,PointerRoutedEventArgs E)
{
if (_isMovingImagE)
_depiction.MoveImagetoPoint(_prevIoUsDraggingPoint,e.GetCurrentPoint(sender as UIElement).position);
_prevIoUsDraggingPoint = e.GetCurrentPoint(sender as UIElement).position;
}
您需要使用 UIElement.CapturePointer(Pointer) 来捕获 Pointer
事件中的 PointerPressed
。
指针只有在按下状态时才能被捕获。
sender.CapturePointer(e.Pointer);
请注意。
一旦被捕获,只有被捕获的元素才会触发与指针相关的事件。
因此记住在不再需要时释放捕获,例如PointerReleased
sender.ReleasePointerCapture(e.Pointer);
以上是大佬教程为你收集整理的PointerReleased 不在 UWP 控制之外工作全部内容,希望文章能够帮你解决PointerReleased 不在 UWP 控制之外工作所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。