Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in code sample: error CS0103: The name 'PointerEvent' does not exist in the current context #2777

Closed
RubenGarcia opened this issue Aug 11, 2023 · 5 comments
Labels
ADO cat: webview2 WebView-related content.

Comments

@RubenGarcia
Copy link

RubenGarcia commented Aug 11, 2023

There is probably a missing using directive; please fix.

error CS0103: The name 'PointerEvent' does not exist in the current context
error CS0103:  The name 'PointerButton' does not exist in the current context

Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

AB#45948334

@mikehoffms
Copy link
Contributor

@RubenGarcia - which section of the article has the related code listing, is it the following code listing?

https://learn.microsoft.com/microsoft-edge/webview2/get-started/hololens2#add-code-to-hook-up-the-buttons

@mikehoffms mikehoffms added cat: webview2 WebView-related content. ADO labels Aug 11, 2023
@RubenGarcia
Copy link
Author

No, quite below that,
https://learn.microsoft.com/en-us/microsoft-edge/webview2/get-started/hololens2#input
this code:

using Microsoft.MixedReality.WebView;

public class WebViewExample : MonoBehaviour, IPointerDownHandler
{
    // WebView setup steps skipped for brevity

    public void OnPointerDown(PointerEventData eventData)
    {
        IWithMouseEvents mouseEventsWebView = webView as IWithMouseEvents;

        // Call hypothetical function which converts the event's x, y into the WebView2's coordinate space.
        var hitCoord = ConvertToWebViewSpace(eventData.position.x, eventData.position.y);

        WebViewMouseEventData mouseEvent = new WebViewMouseEventData
        {
            X = hitCoord.x,
            Y = hitCoord.y,
            Type = PointerEvent.PointerDown,
            Button = PointerButton.Left,
            TertiaryAxisDeviceType = WebViewMouseEventData.TertiaryAxisDevice.PointingDevice
        };

        // Propagate the event to the WebView plugin.
        mouseEventsWebView.MouseEvent(mouseEvent);
    }
}

@RubenGarcia
Copy link
Author

This is the correct code

            Type = WebViewMouseEventData.EventType.MouseDown,
            Button = WebViewMouseEventData.MouseButton.ButtonLeft,

derived from the documentation at
https://learn.microsoft.com/en-us/windows/mixed-reality/develop/advanced-concepts/webview2-plugin-mouse-event-data-class

@mikehoffms
Copy link
Contributor

mikehoffms commented Aug 17, 2023

I'm consulting with Dev to check whether to make that change in the docs ... confirmed, I plan to make that change.

@mikehoffms
Copy link
Contributor

@RubenGarcia - thanks.
https://learn.microsoft.com/en-us/microsoft-edge/webview2/get-started/hololens2#input now reads:
Type = WebViewMouseEventData.EventType.MouseDown,
Button = WebViewMouseEventData.MouseButton.ButtonLeft,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ADO cat: webview2 WebView-related content.
Projects
None yet
Development

No branches or pull requests

2 participants