Click Event in Xamarin Forms

SinghsumitSinghsumit INMember ✭✭
edited November 2017 in Xamarin.Forms

Hello Friends i want to click event, and i am using this code for click event
public class MyClickLabel:Label
{ public event EventHandler Clicked;
public virtual void OnClicked()
{
Clicked?.Invoke(this, EventArgs.Empty);
} }
////////// ////
private void MyClickLabel_Clicked(object sender, EventArgs e)
{
Myclick.Text = "it's Working";
Myclick.ScaleTo(2, 1000);
}
But its not working , i am wasting lost of time. what can i do plz help me.

Posts

  • DavidS67DavidS67 USMember ✭✭

    Hi @Singhsumit

    I think this post will solve your problem : https://forums.xamarin.com/discussion/18342/best-way-to-make-clickable-text

    Instead of using EventHandler, just use TapGestureRecognizer like it is shown as solution of the post.

  • seanydaseanyda GBMember ✭✭✭✭✭
    Label txt = new Label();
                TapGestureRecognizer tap = new TapGestureRecognizer();
                tap.Tapped += (sender, e) => {
                    txt.Text = "Test";
                };
                txt.GestureRecognizers.Add(tap);
    
  • SinghsumitSinghsumit INMember ✭✭

    very thanks @DavidS67 and @seanyda to fast reply,
    public class MyClickLabel:Label
    { public event EventHandler ImageClicked;
    public MyClickLabel()
    { var tgr = new TapGestureRecognizer { NumberOfTapsRequired = 1 };
    tgr.Tapped += ImageOn_Clicked;
    this.GestureRecognizers.Add(tgr);
    }
    public virtual void MyClickLabel_Clicked(object sender,EventArgs e)
    { ImageClicked?.Invoke(sender,e);
    } }
    its Working.

  • CharwakaCharwaka INMember ✭✭✭✭✭

    @Singhsumit said:
    very thanks @DavidS67 and @seanyda to fast reply,
    public class MyClickLabel:Label
    { public event EventHandler ImageClicked;
    public MyClickLabel()
    { var tgr = new TapGestureRecognizer { NumberOfTapsRequired = 1 };
    tgr.Tapped += ImageOn_Clicked;
    this.GestureRecognizers.Add(tgr);
    }
    public virtual void MyClickLabel_Clicked(object sender,EventArgs e)
    { ImageClicked?.Invoke(sender,e);
    } }
    its Working.

    Make sure to mark as answer that help them answer better

  • SinghsumitSinghsumit INMember ✭✭

    yes @Charwaka its working for me. and its helping to creating to custom image entry with Left,Right click

Sign In or Register to comment.