Xamarin Custom Renderer overridden method not called

Poli97Poli97 Member ✭✭

I created a Custom Button Renderer and I extended the Android native method OnPopulateAccessibilityEvent() that should print something on the console when the element receive the accessibility focus but it seems it never got called.

TestRenderer.cs:

` public class TestRenderer: ButtonRenderer
{
public TestRenderer(Context context) : base(context)
{
SetBackgroundColor(Android.Graphics.Color.Cyan);
Console.WriteLine("PIPPO created from android");

        Toast.MakeText(context, "Grabbed Context!", ToastLength.Long).Show();
    }


    public override void OnPopulateAccessibilityEvent(AccessibilityEvent e)
    {
        base.OnPopulateAccessibilityEvent(e);

        if (e.EventType == EventTypes.ViewAccessibilityFocused)
        {
            Console.WriteLine("PIPPO i am in accessibility focus");

        }
    }
}

}`

ITestRenderer.cs
public class ITestRenderer: Xamarin.Forms.Button { public ITestRenderer() { } } }

MainPage.Xaml.cs:
` public partial class MainPage : ContentPage
{

    public MainPage()
    {
        InitializeComponent();

        ITestRenderer prova = new ITestRenderer();
        prova.Text = "PROVA";
        sfondo.Children.Add(prova);                
    }
}

}`

Answers

  • Adeel984Adeel984 Member ✭✭

    Have you export your renderer to your class? if not then add in your TestRenderer page before namespace

    [assembly: ExportRenderer(typeof(ITestRenderer),typeof(TestRenderer))]
    
  • LeoZhuLeoZhu Member ✭✭✭

    you could refer to custom accessibility behavior,maybe it will help you.

  • Poli97Poli97 Member ✭✭

    @Adeel984 said:
    Have you export your renderer to your class? if not then add in your TestRenderer page before namespace

    [assembly: ExportRenderer(typeof(ITestRenderer),typeof(TestRenderer))]
    

    Already did that

  • Poli97Poli97 Member ✭✭

    @LeoZhu said:
    you could refer to custom accessibility behavior,maybe it will help you.

    That example use native Android View, instead I am using Xamarin ViewRenderer, this is the main problem

  • LeoZhuLeoZhu Member ✭✭✭

    @Poli97 in your viewrenderer,you could refer to the native AndroidView,they are both in Android project.

Sign In or Register to comment.