简体   繁体   中英

How to set OnClick on xlabs.buttongroup for Xamarin?

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.

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;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM