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

[Android] Button CustomRenderer OnClick issue

$
0
0

Hello everyone,

after I wrote my own custom renderer for a Button my OnClick events are not triggering anymore. Does anyone had the same problem before or know what I could try?

public class ButtonStyled : Button
{
    public double FontSize { get; set; }

    public ButtonStyled() : base()
    {
        FontSize = 16;
    }
}

public class ButtonStyledRenderer : ViewRenderer<ButtonStyled, global::Android.Widget.Button>
{
    public ButtonStyledRenderer()
    {
    }

    public override void ChildDrawableStateChanged(global::Android.Views.View child)
    {
        base.ChildDrawableStateChanged(child);
        Control.Text = Control.Text;
    }

    protected override void OnElementChanged(ElementChangedEventArgs<ButtonStyled> e)
    {
        base.OnElementChanged(e);

        if (e.OldElement == null) 
        {
            // perform initial setup
            SetNativeControl(new global::Android.Widget.Button(Forms.Context));
        }

        ButtonStyled buttonStyled = this.Element;

        Control.Text = buttonStyled.Text;
        Control.TextSize = (float)buttonStyled.FontSize;
        Control.Typeface = Typeface.CreateFromAsset(Context.Assets, "Fonts/harabara.ttf");
    }
}

Viewing all articles
Browse latest Browse all 58056

Trending Articles



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