Let's say I want to use my custom Android button FlatButton from the FlatUI component on the store.
I can simply write a custom renderer like this:
public class MyButtonRenderer : ButtonRenderer
{
private FlatButton _button;
public MyButtonRenderer()
{
_button = new FlatButton (Forms.Context);
_button.Theme = FlatTheme.Sky ();
}
protected override void OnElementChanged (ElementChangedEventArgs<Button> e)
{
base.OnElementChanged (e);
SetNativeControl (_button);
}
}
However, there are problems:
- It loses all even handlers like the click handler.
- It behaves randomly sometimes, so within a ListView the text displayed will be in a wrong size, but scrolling up and down again makes it renders correctly.
I must be doing something wrong here or missing something, what is it?
Basically, what's the right way of setting my own native control using SetNativeControl without messing things up?