I'm doing a custom renderer in Xamarin. I haven't understood how to get it work. I've followed the following instructions: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/view#Consuming_the_Custom_Control
But it's not explained how to create the android view
CustomRenderer.Droid.CameraPreview
If I create an Android view, it only a cs file and not a .xaml which I also think is strange.
I've created an empty Android view class which I try to set as my Native control from my android renderer:
SetNativeControl(view);
But it will generate a TargetInvocationException.
How is this supposed to work?
-------EDIT-------
When I run the following, nothing happends, I expected the button to be drawn in the view.
public class CameraRenderer : ViewRenderer<Controls.CustomControl, MainApplication.Droid.CameraPreview>
{
private CameraPreview view;
private Context thisContext;
LayoutInflater inflater2;
protected override void OnElementChanged(ElementChangedEventArgs<Controls.CustomControl> e)
{
base.OnElementChanged(e);
view = new CameraPreview(thisContext);
inflater2 = (LayoutInflater)thisContext.GetSystemService(Context.LayoutInflaterService);
inflater2.Inflate(Resource.Layout.layout1, view);
SetNativeControl(view);
}
public CameraRenderer(Context context) : base(context)
{
thisContext = context;
}
}
public class CameraPreview : ViewGroup
{
public CameraPreview(Context context) : base(context)
{
}
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:text="Button test"
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>