在Xamarin.Forms中添加本机视图
我想在我的Xamarin.Forms项目中添加TextInputIt文本,可以添加代码还是XAML?我需要添加对Mono.Android dll的引用?您可以使用来实现它 创建自定义条目控件:在Xamarin.Forms中添加本机视图,xamarin.forms,xamarin.android,Xamarin.forms,Xamarin.android,我想在我的Xamarin.Forms项目中添加TextInputIt文本,可以添加代码还是XAML?我需要添加对Mono.Android dll的引用?您可以使用来实现它 创建自定义条目控件: public class MyEntry : Entry { } 使用自定义控件: <ContentPage ... xmlns:local="clr-namespace:CustomRenderer;assembly=CustomRenderer" ...> ..
public class MyEntry : Entry
{
}
使用自定义控件:
<ContentPage ...
xmlns:local="clr-namespace:CustomRenderer;assembly=CustomRenderer"
...>
...
<local:MyEntry Text="In Shared Code" />
...
</ContentPage>
...
...
在Android上创建自定义渲染器:
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(MyEntry), typeof(MyEntryRenderer))]
namespace CustomRenderer.Android
{
class MyEntryRenderer : EntryRenderer
{
public MyEntryRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.SetBackgroundColor(global::Android.Graphics.Color.LightGreen);
}
}
}
}
使用Xamarin.Forms.Platform.Android;
[assembly:ExportRenderer(typeof(MyEntry)、typeof(MyEntryRenderer))]
名称空间CustomRenderer.Android
{
类MyEntryRenderer:EntryRenderer
{
公共MyEntryRenderer(上下文):基础(上下文)
{
}
受保护的覆盖无效OnElementChanged(ElementChangedEventArgs e)
{
基础。一个要素发生变化(e);
if(控件!=null)
{
Control.SetBackgroundColor(全局::Android.Graphics.Color.LightGreen);
}
}
}
}
这里是供参考的