在 PCL 库中使用自定义渲染器

Using a custom renderer in PCL library

我想在 PCL 中使用我的自定义渲染器。可能吗?或者我可以在此 PCL 中初始化我的自定义渲染器吗?

没有也没有

您在 PCL 中使用的是 - 比方说 - 组件及其抽象。组件的 'materialization'(或不)将由每个平台上的自定义渲染器制作。

一旦它可以在每个平台上显示(或表现)不同,我就看不出有什么理由在独立于平台的实现上使用它。

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/

也许对于真实案例,我们可以提出另一种解决方案。

终于,我找到了解决办法。 我刚刚在我的 PCL 中创建了一个 class 并在 XAML 中使用了它,比方说:

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

即继承Entryclass。在我使用此 PCL 的应用程序中,我创建了一个 class,它继承了 MyHelperEntry:

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

并将此 CustomHelperEntry 用作自定义渲染器。