简体   繁体   中英

PointerCaptureLost c# UWP Windows 10

I am working on UWP Windows 10 application using C#. For some animation I was relying on PointerPressed and PointerReleased events. Hoping that these will be fired in pairs. And I was wrong. Check what Microsoft has to say about this: https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.uielement.pointercapturelost

Now, I am using PointerCaptureLost in place of PointerReleased and it is working fine. Only problem is if I use AddHandler for PointerCaptureLost it shows an error: "UIElement.PointerCaptureLost can only appear on the left hand side of += or -=". It is only working when added as +=.

Any thoughts why it is like this?

You should use UIElement.PointerCaptureLostEvent with AddHandler , because that is the Routed Event ID, which specifies the event. In contrast, x.PointerCaptureLost (where x is the name of the control) is the field that represents the Event Handler itself.

I had no problem using both x.AddHandler(UIElement.PointerCaptureLostEvent, ...) and x.PointerCaptureLost += ... in my code. Moreover, as this link suggests, they both translate to the same call to AddRoutedEventHandler .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM