Skip to content

Showing offset x and y for mouseeventargs #22127

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

Closed
musictopia2 opened this issue May 22, 2020 · 7 comments
Closed

Showing offset x and y for mouseeventargs #22127

musictopia2 opened this issue May 22, 2020 · 7 comments
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@musictopia2
Copy link

I need the ability to show the x and y coordinates of the element being used on and not just the x and y relative to the entire window. I know in javascript, there is the ability of showing that. However, it would be too slow the javascript has to constantly communicate with the c# to give it that information.

@javiercn javiercn added the area-blazor Includes: Blazor, Razor Components label May 22, 2020
@KieranDevvs
Copy link

KieranDevvs commented May 22, 2020

You can use the DOM event OnMouseMove that accepts the argument MouseEventArgs.
The argument contains both the client position and the screen position of the mouse. If you want to find where the mouse is relative to an element, you can do some simple relative maths to calculate it.
image
image

@musictopia2
Copy link
Author

How would somebody figure out the relative position? For the example, i saw the x position was 329 but the width and height was 300. That means if you wanted to know what position relative to that div, i know that javascript has offset x and y but that is not put into the MouseEventArgs.

@KieranDevvs
Copy link

@musictopia2 You can use JS interop to gather the element position and then you can use the delta between the client space to figure out the element mouse position offset. You only need to call the interop once to obtain the position of the element, and then you can bind this logic to events such as window resizing to update this thus bypassing performance concerns within the mouse move event.

I have done some digging and it would appear that the MouseEventArgs is getting Offset values but I don't believe they're in the current release. If you hold on, im sure they will be released soon (hopefully? See more within this current thread: #20478)

@arviedelgado
Copy link

OffsetX/OffsetY is added to MouseEventArgs here #20478

I also need this and actually the first thing I checked after the recent releases.

Apparently, this is only available if targeting .NET 5.0.0-preview.4.

@zHaytam
Copy link
Contributor

zHaytam commented May 25, 2020

When I installed .NET 5 preview4 and changed the TargetFramework in my Blazor WASM project to net5.0, I got the error System.TypeLoadException: Could not resolve type with token 01000010 from typeref (expected class 'System.Threading.Tasks.Task' in assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'), is that normal?

@arviedelgado
Copy link

When I installed .NET 5 preview4 and changed the TargetFramework in my Blazor WASM project to net5.0, I got the error System.TypeLoadException: Could not resolve type with token 01000010 from typeref (expected class 'System.Threading.Tasks.Task' in assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'), is that normal?

.NET 5.0 preview4 currently doesnt support Blazor WASM #22208

@mkArtakMSFT
Copy link
Contributor

This is going to be fixed in .NET 5.0 and the change has already been merged.

@ghost ghost locked as resolved and limited conversation to collaborators Jun 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

6 participants