Forum Xamarin Xamarin.Forms

Type mismatch on Bindableproperty

mchtsmchts Member ✭✭


I have following codes in my custom view class and xaml files:

my custom property:

public static readonly BindableProperty LabelColorProperty = BindableProperty.CreateAttached("LabelColor", typeof(Color), typeof(InfoCell), Color.White, 
    propertyChanged: HandleLabelColorChange);

public static Color GetLabelColor(BindableObject target) {
    return (Color)target.GetValue(LabelColorProperty);

public static void SetLabelColor(BindableObject target, Color value) {
    target.SetValue(LabelColorProperty, value);

private static void HandleLabelColorChange(BindableObject bindable, object oldValue, object newValue){
    //here i do stuff

my xaml tag:
<ce:InfoCell DescriptionText="{Binding DetailCount}" LabelColor="{StaticResource primaryTextColor}"/>

my static resource in App.xaml
<Color x:Key="primaryTextColor">White</Color>

When i pass a color property to LabelColor like White, Black etc. everything is ok. But when i pass a static resource like above
a compile time error occurs like
No property, bindable property, or event found for 'LabelColor', or mismatching type between value and property...

So, what am i missing?

Thanks in advence..

Best Answer


  • mchtsmchts Member ✭✭

    @BillyLiu said:

    Please add a property called LabelColor in your custom view class.
    For example:

        public Color LabelColor
            get { return (Color)GetValue(LabelColorProperty); }
            set { SetValue(LabelColorProperty, value); }

    Yea i realized that after a while :# . Thank you my friend!

Sign In or Register to comment.