I want to my event to trigger when button pressed and released, but I can only find Click event in Xamarin.Forms.
I believe there must be some work around to get this functionality. My basic need is to start a process when button is pressed and stop when released. It seems to be a very basic feature but Xamarin.Forms doesn't have it right now.
I tried TapGestureRecognizer on button, but button is firing only click event.
MyButton.Clicked += (sender, args) =>
{
Log.V(TAG, "CLICKED");
};
var tapGestureRecognizer = new TapGestureRecognizer();
tapGestureRecognizer.Tapped += (s, e) => {
Log.V(TAG, "TAPPED");
};
MyButton.GestureRecognizers.Add(tapGestureRecognizer);
Keep in mind that I need those events to be working in Android and iOS togather.
Since Xamarin.Forms 2.4.0, The events Pressed
and Released
are offered out of the box (see PR).
Note: in order to achieve a Walkie Talkie effect you might want to use Device.BeginInvokeOnMainThread
(or via Prism's IDeviceService
) to invoke consequent actions so the Released
event will get called, otherwise the UI thread might be blocked.
Alternatively, you can declare the event handlers as async
and await
your invocations, to keep the UI thread unoccupied.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With