What can I custom render?

So I can easily custom render Labels, EditTexts, even Views. But it looks like I can't create custom renders for Layouts or RelativeLayout (there is not LayoutRenderer or RelativeLayoutRenderer)??

I am trying to extend my custom renderer by adding labels, views etc onto it. This is easy to on the iOS side, since everything is a view and you can add any views to it. But on Android, you can only add views to a layout.

Does anyone have a solution to this?

Posts

  • LuckyDayLuckyDay USMember ✭✭✭

    I've found that most often the easiest way to do this is to define a custom control on the Forms side and let the built-in renderers handle it. i.e. if you're just looking to have a custom control you don't necessarily need a custom renderer, you can define a subclass of Xamarin.Forms.ContentView that has the UI you're looking for. This also means that you only define the UI once instead of twice (renderers on each platform).

    If you need to do something special/unsupported by the in-box renderers then you should look at custom renderers.

    That said, if you need the custom renderer you should be able to define a ViewRenderer<TElement, TNativeControl>, setting a LinearLayout or some other layout class as the Control. Add your views into the layout, figure out the layout and measuring methods and you should be good to go.

Sign In or Register to comment.