Entry Custom Renderer Frame.Width is always 320

I'm writing a custom Entry class to have Entry controls on iOS only have an underline. In my custom renderer, the Frame.Width is always 320 no matter how wide I make the control. I draw the underline that size and the entry field is obviously longer because the typing goes beyond the end of the underline.

I'm doing the drawing in OnElementChanged. Should I be doing it somewhere else?

What am I doing wrong?

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    The actual size hasn't been confirmed in the event OnElementChanged as the control hasn't been rendered on the screen at that lifecycle.
    You could place your drawing code in the event Draw:

    public override void Draw(CGRect rect)
    {
        base.Draw(rect);
    
        // Place your drawing code here
    }
    

    You could get the real size and position here.

Sign In or Register to comment.