[英]Integrate Android View as custom control into Xamarin.Forms
我在项目中使用Xamarin Forms。
基本上,我想在表单中集成自定义控件 。 该组件具有Android视图(axml),我找不到将其包含到共享Xamarin Forms项目中的方法。
我试图创建一个自定义渲染器:
[assembly: ExportRenderer(typeof(RadialControl), typeof(RadialControlRenderer))]
namespace EA.Indemnisation.Renderers
{
public class RadialControlRenderer : ViewRenderer
{
protected override void OnDraw(Android.Graphics.Canvas canvas)
{
base.OnDraw(canvas);
SetContentView(Resource.Layout.Radial); // How can I include my view as component into the form?
var bigRadialProgress = FindViewById<RadialProgressView>(Resource.Id.bigProgress);
var smallRadialProgress = FindViewById<RadialProgressView>(Resource.Id.smallProgress);
var tinyRadialProgress = FindViewById<RadialProgressView>(Resource.Id.tinyProgress);
}
}
}
那对我没有帮助,因为我无法获取Android视图,无法与其交互并将其包含在表单中。
我还研究了如何将Android.Views.View
转换为Xamarin.Forms.View
但我找不到解决方法。
将自定义控件集成到Xamarin Forms应用程序的方法是什么?
您开始朝正确的方向前进。 覆盖OnElementChanged,因为您应该在那里创建Android View。
就像是:
protected overrie void OnElementChanged(ElementChangedEventArgs<RadialControl> e)
{
if (Control == null) {
YourView yourView = new YourView(base.Context);
SetNativeControl(yourView );
}
// update and/or bind properties & events
....
}
进一步捕获RadialControl的属性更改,您将覆盖OnElementPropertyChanged;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.