[xamarin][UWp][custom renderer] OnElementChanged not invoking

sumithsudesansumithsudesan USMember ✭✭

Hi,

i created extend the button with custom renderer. But its not working in uWP platform. The 'OnElementChanged()' is not invoked.
Its working properly in all other platform.

what i do?

[assembly: ExportRenderer(typeof(UICControl.UICButton), typeof(UIC.Lib.UICRenderer))]


namespace UIC.Lib
{
    public class UICRenderer : ButtonRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e)
        {
            base.OnElementChanged(e);
            if (Control == null || Element == null)
                return;


           var btnControl = (UICControl.UICButton)e.NewElement;
                if (btnControl != null)
                {
                 btnControl.TextColor = Xamarin.Forms.Color.White;
                  btnControl.BackgroundColor = Xamarin.Forms.Color.Black;
                    btnControl.BorderWidth = (double)(1);
                    btnControl.BorderColor = Xamarin.Forms.Color.LightBlue;
                    btnControl.BorderRadius = (int)(0);
                    btnControl.FontFamily = "Arial";
                    btnControl.FontAttributes = FontAttributes.Bold;
               }    

      }




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

            var btnControl = sender as Xamarin.Forms.Button;

            if ((e.PropertyName == UICButton.IsEnabledProperty.PropertyName.ToString()))
            {
                if (Element.IsEnabled)
                {
                    btnControl.BackgroundColor = Xamarin.Forms.Color.Black;
                }
                else
                {
                    btnControl.BackgroundColor = Xamarin.Forms.Color.Gray;
                }
            }
        }
}

}

Answers

  • Sumit_SharmaSumit_Sharma USMember ✭✭✭

    try this, maybe it will work

    In you renderer class in library project add this

    public static void Init() { }

    and in you main project where you are using this library project

    In UWP Main.cs

    just before LoadApplication(Xamarin.Forms.App())

    add this line

    UIC.Lib.UICRenderer.Init();

    Give it a try

  • sumithsudesansumithsudesan USMember ✭✭

    @Sharma.Sumit said:
    try this, maybe it will work

    In you renderer class in library project add this

    public static void Init() { }

    and in you main project where you are using this library project

    In UWP Main.cs

    just before LoadApplication(Xamarin.Forms.App())

    add this line

    UIC.Lib.UICRenderer.Init();

    Give it a try

    'UICControl.UICButton' and 'UIC.Lib.UICRenderer' are in separate libraries.
    my idea is to create common 'UICButton' class for all platforms and seperate 'UICRenderer' class for platforms.

  • sumithsudesansumithsudesan USMember ✭✭

    actually its working in debug mode and not working in release mode

  • sumithsudesansumithsudesan USMember ✭✭
    edited July 2017

    implementation

  • sumithsudesansumithsudesan USMember ✭✭

    @Sharma.Sumit said:
    try this, maybe it will work

    In you renderer class in library project add this

    public static void Init() { }

    and in you main project where you are using this library project

    In UWP Main.cs

    just before LoadApplication(Xamarin.Forms.App())

    add this line

    UIC.Lib.UICRenderer.Init();

    Give it a try

    do i need to add 'public static void Init() { }``' all 2 renderer class (android and uwp)?

Sign In or Register to comment.