Storing Controllers Inside Xamarin Forms Custom Renderers

AdamFisherAdamFisher USMember ✭✭

I am creating a Xamarin Forms custom renderer. I need to invoke and manipulate a native iOS view controller inside the custom renderer.

I see two possible options :

  1. Create a custom class and extend UIView and set that as the native control in the custom renderer?
  2. Or should I just set a property directly in the custom renderer? This seems to be what most people do.

After all the examples I have seen it looks like the same renderer can possibly be reused over many different invocations of a forms element so they should not hold state. Especially if you add 10 different declarations of the same element to your page and each element will need its own renderer with its own state. The reason I think this is because of the way OnElementChanged() has to be handled. Am I off base on this?

Best Answer

Answers

  • AdamFisherAdamFisher USMember ✭✭

    Thanks Tekton. That answers my question implicitly through the github repo linked to in that article. It follows the same convention a lot of other people have been following and just declaring fields/properties directly in the custom renderer which must be safe.

Sign In or Register to comment.