locked
Custom Control and Data Binding RRS feed

  • Question

  • User385594 posted

    Hi, when I set value of data binding in field custom, i get this error "No property, bindable property, or event found for 'ActivedEffect', or mismatching type between value and property."

    My custom control:

        namespace App.Customers
        {
        class EffectFrame :  Frame
        {
            public BindableProperty ActivedEffectPropiety = BindableProperty.Create(nameof(ActivedEffect),
                                                                                typeof(bool),
                                                                                typeof(EffectFrame),
                                                                                false,
                                                                                BindingMode.TwoWay);
        public bool ActivedEffect
        {
            get
            {
                return (bool)GetValue(ActivedEffectPropiety);
            }
            set
            {
                SetValue(ActivedEffectPropiety, value);
            }
        }
    
        protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            if (propertyName.Equals(nameof(ActivedEffect)))
            {
                if (ActivedEffect)
                {
                    this.FadeTo(1, 500);
                }
                else
                {
                    this.FadeTo(0, 500);
                }
            }
    
    
            base.OnPropertyChanged(propertyName);
            }
    
        }
    }
    
    <?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
             xmlns:Image="clr-namespace:FFImageLoading.Svg.Forms;assembly=FFImageLoading.Svg.Forms"
             xmlns:Custom="clr-namespace:App.Customers"
             x:Class="App.Views.Example">
    <StackLayout>
        <Custom:EffectFrame  BackgroundColor="White" 
                             VerticalOptions="End" 
                             HorizontalOptions="FillAndExpand"
                             CornerRadius="10"
                             Margin="23,0,23,14"
                             Padding="0"
                             ActivedEffect="{Binding InfoVisible}">
            <StackLayout Spacing="0">
                <StackLayout Orientation="Horizontal"
                             Margin="26,22,0,0">
                    <Label Text="Text"
                           TextColor="#ED1C24"
                           FontSize="15">
                    </Label>
                </StackLayout>    
            </Custom:EffectFrame>
        </StackLayout>
    </ContentPage>
    

    The field "InfoVisbile" is a bool in ViewModel

    Any idea?

    Thursday, January 2, 2020 7:07 PM

Answers

  • User369979 posted

    There is a spelling mistake in your bindable property. It must end with Property this is a fixed grammar. Moreover, it has to be started with the keywords: static readonly. https://docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/bindable-properties#create-a-property

    So here is the correct definition:

    public static readonly BindableProperty ActivedEffectProperty = BindableProperty.Create(nameof(ActivedEffect),
                                                                        typeof(bool),
                                                                        typeof(EffectFrame),
                                                                        false,
                                                                        BindingMode.TwoWay);
    public bool ActivedEffect
    {
        get
        {
            return (bool)GetValue(ActivedEffectProperty);
        }
        set
        {
            SetValue(ActivedEffectProperty, value);
        }
    }
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, January 3, 2020 2:42 AM