1
votes

I am using Xfx.Controls in my xamarin forms application for floating label entry. Its working fine on android,

but when running on iOS after filling text on floating-point entry and close the page will throw an exception.

System.NullReferenceException: Object reference not set to an instance of an object at Xfx.Controls.iOS.Renderers.XfxEntryRendererTouch.OnElementChanged

How to solve this issue?

3
If you want to use the floating label without plugin ,update xamarin and provide visual="Material" for your normal entry in xaml.Anand

3 Answers

0
votes

This is the issue inside the plugin so you can either get familiar with the plugin code and fix the error yourself all to submit the issue on their github and wait for it to be fixed eventually.

0
votes

As per a comment in an open issue:

this is because in xamarin 4 Dispose is called correctly on the renderer (wonder why it didn't in previous versions though)... Control is null when getting in OnElementChanged, so the unsubscribes fail. So the onelementchanged should check if Control != null where applicable

So a temporary workaround would be using a custom renderer like this:

public class CustomXfxEntryRendererTouch : XfxEntryRendererTouch
    {
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                SetElement(null); //trigger elementchange before base dispose happens https://github.com/XamFormsExtended/Xfx.Controls/issues/97
            }

            base.Dispose(disposing);
        }
    }
0
votes

Make sure to add the ExportRenderer. I'm brand spanking new to xamarin and C#, so I figured this would help those still learning. Feed control being used in page (XfxEntry) and your custom renderer (CustomXfxEntryRendererTouch).

[assembly: ExportRenderer(typeof(XfxEntry), typeof(CustomXfxEntryRendererTouch))]
namespace Application.iOS.CustomRenderer
{
    public class CustomXfxEntryRendererTouch : XfxEntryRendererTouch
    {
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                SetElement(null); //trigger elementchange before base dispose happens https://github.com/XamFormsExtended/Xfx.Controls/issues/97
            }

            base.Dispose(disposing);
        }
    }
}