Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Custom Control Error only by Color Property

Hi folks, i get this Error
XFC0009 No property, BindableProperty, or event found for "Attractive_BarColorLvl_1", or mismatching type between value and property.
if i try to set a Binding to my Property (Attractive_BarColorLvl_1).

Even code with small adjustments works wonderfully with ImageSource and String.

What i do wrong ?

My Code:

public static readonly BindableProperty BarColorProperty = BindableProperty.Create(
propertyName: nameof(Attractive_BarColorLvl_1),
returnType: typeof(Color),
declaringType: typeof(RatingBar),
defaultValue: default(Color),
defaultBindingMode: BindingMode.OneWay,
propertyChanged: ImageSourcePropertyChanged);

    public Color Attractive_BarColorLvl_1
    {
        get
        { return (Color)GetValue(BarColorProperty); }
        set
        { SetValue(BarColorProperty, value); }

    }

    private static void ImageSourcePropertyChanged(BindableObject bindable, object oldValue, object newValue)
    {
        var control = (RatingBar)bindable;
        control.Attractive_BarLvl_1.BackgroundColor = Color.FromHex(newValue.ToString());
    }

Best Answer

  • tareqelzoubitareqelzoubi Member ✭✭
    edited March 1 Accepted Answer

    Hi @JoinDev try to change
    **from ** control.Attractive_BarLvl_1.BackgroundColor = Color.FromHex(newValue.ToString());
    **to ** control.Attractive_BarLvl_1.BackgroundColor = (Color)newValue;

Answers

  • tareqelzoubitareqelzoubi Member ✭✭
    edited March 1 Accepted Answer

    Hi @JoinDev try to change
    **from ** control.Attractive_BarLvl_1.BackgroundColor = Color.FromHex(newValue.ToString());
    **to ** control.Attractive_BarLvl_1.BackgroundColor = (Color)newValue;

  • JoinDevJoinDev Member

    Thanks it works

Sign In or Register to comment.