How to set OnClick on xlabs.buttongroup for Xamarin?

506 views Asked by At

Trying to figure out how to use XLabs ButtonGroup for Xamarin Forms. https://github.com/XLabs/Xamarin-Forms-Labs/wiki/ButtonGroup

I can't find an event handler or any way to set a listener for a click.

The sample code for how to use the button just skips over that detail. https://github.com/XLabs/Xamarin-Forms-Labs/blob/master/Samples/XLabs.Sample/Pages/Controls/ButtonGroupPage.cs

What am I missing?

Thanks, Brad.

1

There are 1 answers

0
Alessandro Caliaro On BEST ANSWER

If I remember correctly, I have add these rows

    public delegate void ButtonClickedHandler(int index);
    public event ButtonClickedHandler Clicked;
    protected void OnClicked(int index){
        if (Clicked != null) {
            Clicked (index);            
        }
    }

and modified this method

    /// <summary>
    /// Sets the selected button.
    /// </summary>
    /// <param name="o">The o.</param>
    private void SetSelectedButton(object o)
    {
        if((int)o != SelectedIndex)
            OnClicked ((int)o);
        SelectedIndex = (int)o;
    }