1

I want to use my custom renderer inside a PCL. Is it possible? Or can I initialize my custom renderer inside this PCL?

2 Answers2

1

No and No.

What you use in PCL is - let's say - component and it's abstraction. The 'materialization' (or not) of the component will be made by custom renders on each platform.

I can't see a reason to use it on a platform-independent implementation once it can be shown (or to behaves) differently on each one.

Custom Renderers let developers override this process to customize the appearance and behavior of Xamarin.Forms controls on each platform.

https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/custom-renderer/

Maybe with a real case, we can suggest another solution.

Diego Rafael Souza
  • 5,241
  • 3
  • 23
  • 62
  • 1
    Thank you for the answer! I've just wanted to do a common staff for several apps (for example, settings activity). I did this with custom renderers for one app, and in another app i need to use the same settings. And i don't want to copy-past the source code. Maybe you could suggest any solutions for such an issue?.. – Денис Чорный Feb 16 '18 at 05:34
  • 1
    @ДенисЧорный It sounds like a package or a personal plugin/toolkit. You can do it too. [Here's a good video about this topic from James Montemagno's youtube channel](https://www.youtube.com/watch?v=eCmgy7TQd00). – Diego Rafael Souza Feb 16 '18 at 12:40
0

Finally, I've found a solution. I've just created a class in my PCL and used it in XAML, let's say:

public class MyHelperEntry : Entry { public MyHelperEntry() { } }

that inherits Entry class. And in an App, where I use this PCL, I've created a class, that inherits MyHelperEntry:

public CustomHelperEntry : MyHelperEntry { public CustomHelperEntry() { } }

and used this CustomHelperEntry as a custom renderer.