c# - 如何在 Xamarin Forms PCL 中使用 native Android ImageView?

标签 c# android xamarin xamarin.forms

我是 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/

相关文章:

c# - VB 2008 将字符串 "08:30:00"转换为日期时间 "08:30:00"

c# - ObservableCollection 键上的排序扩展方法

android - 如何使用 android 中的下载管理器将下载的图像存储在内部存储中

java - 如何控制自定义 jar 库的使用?

android - 事件点击 android.support.design.widget.NavigationView 上的项目

C# - Marshall 并将 void 指针传递给从 C# 调用的 C 函数

c# - 为什么 HttpClient.PostAsync() 没有在控制台应用程序中完成,但在 Web 应用程序中完成?

android - 将 url 加载到 WebView 时显示进度栏

ios - Xamarin.iOS 应用程序启动崩溃,控制台中没有崩溃日志和失败消息

android - 为什么我在开始调试 Xamarin Android 应用程序时无法命中断点?