我是 Xamarin 新手,但学得很快。我有一个希望是一个简单的问题。我知道我可以使用自定义渲染器自定义每个平台的 Xamarin Forms 控件,而且我还知道我可以使用具有 0 参数构造函数和依赖项服务的 native 控件。
我的问题是,如何在我的 Xamarin Forms PCL 应用程序中使用 native 控件(特别是 Android ImageView...最终显然是 WinPhone 和 iOS 对应控件)?
一个非常简单的示例将大有帮助,因为我只是无法理解如何定义一个接口(interface),该接口(interface)将在特定于平台的控件上设置缓冲、图像源等参数。
感谢您的帮助!
最佳答案
在 Xamarin Forms 的最新更新中,这是一项新添加的功能。 您可以在博客中阅读更多相关信息 - Embedding Native Controls into Xamarin.Forms 。
您还可以在 Native Embedding - Adding Platform-Specific Controls to a Xamarin.Forms Layout 找到 sample
在 Android 上,以下代码示例演示了如何将 TextView 添加到 StackLayout 和 ContentView:
var textView = new TextView (Forms.Context) { Text = originalText, TextSize = 14 };
stackLayout.Children.Add (textView);
contentView.Content = textView.ToView();
为此,您必须使用共享项目模板而不是 PCL。对于 PCL,您必须使用自定义渲染。
关于c# - 如何在 Xamarin Forms PCL 中使用 native Android ImageView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28753523/