Balasubramanian
Balasubramanian

Reputation: 73

OnElementPropertyChanged is not triggered in iOS custom renderer

OnElementPropertyChanged is not triggered in iOS custom renderer.

I have created a class library. In my Customer Renderer class i have override a OnElementPropertyChanged and this should be called whenever the Property of my View gets changed.

XamarinForms:

public class CustomControl : View
{
    public int PageNumber
    {
        get { return (int)GetValue(PageNumberProperty); }
        set { SetValue(PageNumberProperty, value); }
    }

    public static readonly BindableProperty PageNumberProperty =
        BindableProperty.Create<CustomControl, int>(p => p.PageNumber, 0, BindingMode.Default, null, null);


}

CustomRenderer Class iOS:

 [assembly: ExportRenderer(typeof(CustomControl), typeof(CustomRenderer))]

 namespace XForms.iOS
{    
internal class CustomRenderer : ViewRenderer<CustomControl, UIScrollView>
{

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


    }
    protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        base.OnElementPropertyChanged(sender, e);
    }
}

}

Can anyone tell what i am doing wrong?

Upvotes: 2

Views: 1835

Answers (1)

Krumelur
Krumelur

Reputation: 33048

Please double check that it is really using the custom renderer by putting a breakpoint into it.

Next make sure that you change proper (PageNumber) after creation of the UI element. During the creation process, property change notifications will not be sent. A similar case is described in the Xamarin forums.

Upvotes: 1

Related Questions