user19432624
user19432624

Reputation:

No property, BindableProperty, or event found for "IsChecked", or mismatching type between value and property

The control I created doesn't have an IsChecked property, so I created it, and when I try to bind to it, I get this error. Can you tell me where is wrong?

 <Ctrl:CtrlImageToggleButton
                                            x:Name="xEnablePV"
                                            Grid.Row="7"
                                            Grid.Column="1"
                                            HorizontalOptions="Start"
                                            IsChecked="{Binding EnablePV}"
                                            ToggleOffImageSource="btn_off.png"
                                            ToggleOnImageSource="btn_on.png" />



   public class CtrlImageToggleButton : ImageButton
        {
            private bool bCheck = false;
            public delegate void eStatusChanged();
            public event eStatusChanged event_StatusChanged;
                      
            public bool IsChecked 
            {
                get
                {
                    return bCheck;
                }
                set
                {
                    bCheck = value;
                    SetValue(IsCheckedProPerty, value);
    
                    if (this.event_StatusChanged != null)
                    {
                        this.event_StatusChanged();
                    }
                }       
            }
    
    
            public static readonly BindableProperty IsCheckedProPerty = BindableProperty.Create(
                                                              propertyName: "IsCheckedProPerty",
                                                              returnType: typeof(bool),
                                                              declaringType: typeof(CtrlImageToggleButton),
                                                              defaultValue: false,
                                                              defaultBindingMode: BindingMode.TwoWay,
                                                              propertyChanged: IsCheckedProPertyChanged);
    
            private static void IsCheckedProPertyChanged(BindableObject bindable, object oldValue, object newValue)
            {
                (bindable as CtrlImageToggleButton).IsChecked = (bool)newValue;
            }       
        }
    }

오류 XFC0009 No property, BindableProperty, or event found for "IsChecked", or mismatching type between value and property. POP D:\ProgramSrc\POP Renewal\POP\POP\Component\Spectrum\Spectrum_OptionPage.xaml 196

Upvotes: 1

Views: 1275

Answers (1)

FreakyAli
FreakyAli

Reputation: 16479

There is a fixed naming convention for Bindable properties that you have to follow so your property name should be something like shown below:

 public static readonly BindableProperty IsCheckedProperty = BindableProperty.Create(
                                              propertyName: nameof(IsChecked),
                                              returnType: typeof(bool),
                                              declaringType: typeof(CtrlImageToggleButton),
                                              defaultValue: false,
                                              defaultBindingMode: BindingMode.TwoWay,
                                              propertyChanged: IsCheckedPropertyChanged);

Upvotes: 2

Related Questions