How to capture mouse in onmousemove
event in Blazor like UIElement.CaptureMouse()
in WPF?
... in Blazor like UIElement.CaptureMouse()
The closest match would be Element.setPointerCapture()
In order to use it you will need to get an ElementReference in Blazor with @ref
and a JS method to invoke setPointerCapture on it. You need to pass a pointerId that you get from PointerEventArgs.
Do not use the Mouse* related events/methods, they are more or less deprecated in JS.
So you can start with something like:
<div @ref="myTarget" @onpointerdown="StartCapture"> ... </div>
@code{
ElementReference myTarget;
async Task StartCapture(PointerEventArgs args)
{
await JSRuntime.InvokeVoidAsync("myJsFunctions.capturePointer",
myTarget, args.PointerId);
}
}