Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Extend Label control - adding a Click event handler

$
0
0

I need a control that can respond to both single click / tap and double click / tap. I found out I cannot use TapGestureRecognizer if I want to handle both single and double clicks / taps. So, I am trying to extend a Label control, adding a Click event handler. I tried the following code, but the event does not fire. Any suggestions? Thanks!

in LabelClickable.cs:
...
public class LabelClickable : Label
{
public event EventHandler Clicked;
public virtual void OnClicked()
{
Clicked?.Invoke(this, EventArgs.Empty);
}
}
...

in MainPage.XAML:
...
<local:LabelClickable Text="0" Clicked="Button_Clicked"/>
...

and in MainPage.Xaml.cs:
...
private void Button_Clicked(object sender, EventArgs e)
{
//do something;
}
...


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>