Reputation: 3198
I am using Xamarin Forms in my project.
Basically I want to integrate a custom control in my form. This component is given with an Android view (axml) and I cannot find a way to include it into my shared Xamarin Forms project.
I tried to create a custom renderer:
[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);
}
}
}
That didn't help me because I am not able to get the Android view, interact with it and include it in my form.
I also looked at how to convert an Android.Views.View
into a Xamarin.Forms.View
but I cannot find a way to do that.
What is the way to integrate a custom control into a Xamarin Forms app?
Upvotes: 1
Views: 1511
Reputation: 3240
You started in proper direction. Overrid OnElementChanged as there you are supposed to create your Android View.
Something like:
protected overrie void OnElementChanged(ElementChangedEventArgs<RadialControl> e)
{
if (Control == null) {
YourView yourView = new YourView(base.Context);
SetNativeControl(yourView );
}
// update and/or bind properties & events
....
}
Furthermo to catch RadialControl's property changes you'd override OnElementPropertyChanged;
Upvotes: 2