Reputation: 2703
In my Xamarin.Forms app, I have a view in my StackLayout
. I want to make an effect so that when the user presses on the StackLayout
the background changes color, and then reverts the color back when the user releases his/her finger, for a "flash" effect.
I was advised that since views don't have an "on pressed" event, I would have to use a custom renderer. But I don't know how to make a custom renderer for a StackLayout
?
Upvotes: 1
Views: 419
Reputation: 12169
You don't really need a CustomRenderer
to have a "on pressed" event on your StackLayout
, you can use TapGestureRecognizer
instead.
<StackLayout>
...
<StackLayout.GestureRecognizers>
<TapGestureRecognizer
Tapped="OnTapGestureRecognizerTapped" />
</StackLayout.GestureRecognizers>
</StackLayout>
You can read more about GestureRecognizers
in the official documentation.
P.S.: If you really need to react to "finger release" than you might need an Effect or a CustomRenderer.
Upvotes: 2