How to prevent drag outside of a given boundary .net Maui Android.

I have been looking for a way to (as the title suggests) prevent a draggable control from going past a boundary. Be that a grid, container, circle etc. Could even just be limited to so many pixels from the controls start position. I am also unsure of the proper terminology of such thing, and as such it has slowed down research into the matter. Any assistance would be appreciated!
3 Replies
Absent_Reality
Absent_RealityOP10mo ago
Small progress
c#
OnDragStarting ( object sender, DragStartingEventArgs e)
{
var x = CounterBtn.X; var y = CounterBtn.Y;

Label1.Text = ($"{x} \n {y});
}
c#
OnDragStarting ( object sender, DragStartingEventArgs e)
{
var x = CounterBtn.X; var y = CounterBtn.Y;

Label1.Text = ($"{x} \n {y});
}
Does give me X = 30 Y = 369.5454 More investigation shall commence.. Nvm. On adding a tapped event and CounterBtn.TranslateTo (0, 50, 1000) the X/Y still reads the same when dragged from new position. Point? point = e.GetPosition(null); does reflect the +50 value, however, since it's based on point of contact, the value can fluctuate a lot.
Absent_Reality
Absent_RealityOP10mo ago
think i figured it out to a point. Drag event has to have a drop listener to relay position info to. So on control is the <DragGestureRecognizer DragStarting="DragStarting" DropCompleted="DropCompleted" >
Absent_Reality
Absent_RealityOP10mo ago
and the view (in my case the grid) <DropGestureRecognizer DragLeave="DragLeave" DragOver="DragOver" Drop="Drop"> Note: there are a lot of extra things in that code where I was just checking what numbers it would output, but hopefully someone may find it all useful.
Want results from more Discord servers?
Add your server