Xamarin.Forms MasterDetailPage custom renderer

1.5k views Asked by At

I am trying to write a custom renderer for the MasterDetailPage in Xamarin.Forms (v. 2.3.3.175). I need to adjust the default Master width which is way too large compared to its content.

Unfortunately I get a "System.NullReferenceException" as soon as the custom renderer class is created. I have cleaned everything and I still get the error. It seems that simply deriving my class from MasterDetailRenderer is causing the issue.

For the sake of testing I have stripped my custom renderer down to as follows:

[assembly: Xamarin.Forms.ExportRenderer(typeof(Xamarin.Forms.ExMasterDetailPage), typeof(ExMasterDetailRenderer))]
namespace MDPageTest.Droid.Renderers {
    public class ExMasterDetailRenderer : MasterDetailRenderer
    { }
}

Nothing else! Still the error occurs. Either commenting the attribute line (hence disabling the custom renderer) or removing the class derivation solves the issue and the app starts without any other error.

Is anybody else experiencing such an issue? Any clue on how to fix it ?

Thank you in advance. Cheers,

M.

1

There are 1 answers

0
Paul On

The cause for this is likely that your MainActivity inherits from FormsAppCompatActivity instead of FormsApplicationActivity. You should be able to resolve this by making your custom renderer inherit from MasterDetailPageRenderer from the Xamarin.Forms.Platform.Android.AppCompat namespace.