Xamarin.Forms creates two instances of renderer for one control instance.

Yuri.3926Yuri.3926 USMember ✭✭

I've create a simple view in XF project just to make a renderer for this to use native Android features.

public class CollectionView : View
{
    public CollectionView()
    {
        Margin = new Thickness(0, 10, 0, 0);
    }
}

I am using this view only once for all project in one xaml file. Next I've created a custom renderer for this view in my Android project.

[assembly: ExportRenderer(typeof(CollectionView), typeof(CollectionViewRenderer))]
namespace Project.Forms.Droid.Renderers
{
    public class CollectionViewRenderer : ViewRenderer<CollectionView, Android.Views.View>
    {
    ...
    }
}

For some reason ctor of CollectionViewRenderer calls two times. I have some event subscriptions inside and when event triggers code from CollectionViewRenderer runs two times in two different instances. Does anybody know why this may happens and how to fix this?

Answers

Sign In or Register to comment.