Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Is BindableProperty sensitive to field or property changes inside i'ts object?

LeloLelo Member ✭✭✭
public class Entry : Xamarin.Forms.Entry
    {
        public Color Color { get => (Color)GetValue(ColorProperty); set => SetValue(ColorProperty, value); }
        public BindableProperty ColorProperty = BindableProperty.CreateAttached("Color", typeof(Color), typeof(Entry), new Color(255, 255, 255));
    };

    public class Color
    {
        public int R { get; set; }
        public int G { get; set; }
        public int B { get; set; }
        public int A { get; set; }

        public Color(int r, int g, int b)
        {
            R = r;
            G = g;
            B = b;
        }
    }

I fear the ColorProperty will not detect changes made to the properties inside the color class? If so what would be the easiest way to achieve that? My intention is to put some properties on Entry (custom) that can be used inside the custom renderers on each platform.

Best Answer

  • LeloLelo Member ✭✭✭
    Accepted Answer

    First of all the BindableProperty's should be static. A mistake by me.

    Secondly it appears I have to create a new instance of Color that I set it to - otherwise property changed will not be called properly to get received in the renderers.
    If a property changed could be sent by change of R, G, B A specific properties it would be great.

Answers

  • LeloLelo Member ✭✭✭
    Accepted Answer

    First of all the BindableProperty's should be static. A mistake by me.

    Secondly it appears I have to create a new instance of Color that I set it to - otherwise property changed will not be called properly to get received in the renderers.
    If a property changed could be sent by change of R, G, B A specific properties it would be great.

  • ColeXColeX Member, Xamarin Team Xamurai

    Please mark your solution as answer .@Lelo

  • LeloLelo Member ✭✭✭
    edited April 2
    Color = Color.New();
    
Sign In or Register to comment.