Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Event for Custom Control (button)

$
0
0

Hi guys.

I have around 10 buttons, which all look the same, so I thought I will make CustomControl for my button for further usage and easier changes.
I didn't thought I will struggle so much with simple adding event. I have spend few hours currently on it, and still don't see solution.
I would be greatful if you could tell me what I am doing wrong...

Here is my Custom button class:

public partial class CircleButton : ContentView
{
    public event EventHandler Clicked;

    public CircleButton ()
    {
        InitializeComponent ();

        TapGestureRecognizer tap = new TapGestureRecognizer();
        tap.Command = new Command(OnClicked);
        GestureRecognizers.Add(tap);
    }

    public void OnClicked(object sender)
    {
        if (Clicked != null)
        {
            this.Clicked(this, EventArgs.Empty);
        }
    }

In MainPage.xml I have added code:

    <controls:CircleButton x:Name="Btn21" Grid.Row="0" Grid.Column="1" ButtonText="21" Clicked="CircleButton_Clicked_1" >
</controls:CircleButton>

and in MainPage.cs file:

    private void CircleButton_Clicked_1(object sender, EventArgs e)
    {
        pageNumber.Text = "$$";
    }

Viewing all articles
Browse latest Browse all 204402

Trending Articles



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