Search code examples
xamarin.formsxamarin.ioscustom-renderer

Xamarin access property of a custom renderer from xaml


I have an ios custom render for the xamarin editor and im trying to set the Control.ScrollEnabled property to be true on some page and false on other pages.

[assembly: ExportRenderer(typeof(ExtendedEditor), typeof(ExtendedEditorRenderer))]
namespace My.iOS.Renderers
{
    public class ExtendedEditorRenderer : EditorRenderer
    {
        public ExtendedEditor ExtendedEditorElement => Element as ExtendedEditor;

        protected override void OnElementChanged(ElementChangedEventArgs<Editor> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                Control.ScrollEnabled = false;
            }
        }
    }
}

Above is my code the customer renderer. As you can see the ScrollEnabled property is always set to false. Is there a way that i can get access to these properties, such as, scrollenable, bordercolor, backgroundcolor, etc.. and change them from XAML?


Solution

  • You will need to create those Properties/BindableProperties on your ExtendedEditor control and then access those in your renderer using the ExtendedEditorElement property you created.

    When you have the properties declared in your ExtendedEditor class, you can access those like below:

    protected override void OnElementChanged(ElementChangedEventArgs<Editor> e)
    {
        base.OnElementChanged(e);
    
        if (e.NewElement != null)
        {
            Control.ScrollEnabled = ExtendedEditorElement.ScrollEnabled;
        }
    }