locked
Type mismatch on Bindableproperty RRS feed

  • Question

  • User371970 posted

    Hi,

    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..

    Wednesday, August 8, 2018 7:31 AM

Answers

  • User364855 posted

    @mchts

    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); }
        }
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, August 10, 2018 7:21 AM

All replies

  • User364855 posted

    @mchts

    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); }
        }
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, August 10, 2018 7:21 AM
  • User371970 posted

    @BillyLiu said: @mchts

    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!

    Friday, August 10, 2018 7:28 AM