question

ParsaGachkar-5677 avatar image
0 Votes"
ParsaGachkar-5677 asked KyleWang-MSFT edited

BindableProperty Cannot resolve property "x" on type "y (property missing or missing accessors)", Am I missing somthing?

I've Implemented an Effect to Make my Entries Round. and it's working if I assign it to my entries. now I'm trying to Implement a global style to automatically assign it to all entries.

According to Microsoft documentation, I need to implement a static Class containing some static Bindable Properties and static Getter Setter Methods to assign and read property values from my Views.

 public static class RoundEffect{
         public static BindableProperty IsRound = BindableProperty.CreateAttached("IsRound",typeof(bool),typeof(RoutingEffect),true,propertyChanged: PropertyChanged);
    
         public static bool GetIsRound(BindableObject view)
         {
             return (bool)view.GetValue(IsRound);
         }
    
         public static void SetIsRound(BindableObject view, bool value)
         {
             view.SetValue(IsRound,value);
         }
         private static void PropertyChanged(BindableObject bindable, object oldvalue, object newvalue)
         {
             var value = (bool) newvalue;
             var control = bindable as Entry;
             if (control != null)
             {
                 var effect = control.Effects.FirstOrDefault(q => q is CustomEditTextPlatformEffect);
                 if (value && effect == null)
                 {
                     control.Effects.Add(new CustomEditTextPlatformEffect());
                 }
                 else if(!value && effect != null)
                 {
                     control.Effects.Remove(effect);
                 }
             }
         }
     }

here is the class I've implemented. and I'm trying to use it like this:

 <Style TargetType="Entry">
                 <Setter Property="FontFamily" Value="{StaticResource someFont}"></Setter>
                 <Setter Property="effects:RoundEffect.IsRound" Value="True"></Setter>
             </Style>

I'm getting 0 errors while building but if I try to run it on my android emulator I'm getting this error:

 Error    XFC0001    Cannot resolve property "IsRound" on type "RoundEffect (property missing or missing accessors)".

I'll Really appreciate it if anyone could help me see what am I missing, I've already tried cleaning and rebuilding my solution!




dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

KyleWang-MSFT avatar image
1 Vote"
KyleWang-MSFT answered KyleWang-MSFT edited

Hi ParsaGachkar-5677,

Welcome to our Microsoft Q&A platform!

When you create an attached property, you need to append "Property" to your custom property name.

So in your project, the "IsRound" should be changed to "IsRoundProperty" as follows:

 public static BindableProperty IsRoundProperty = 
             BindableProperty.CreateAttached("IsRound", typeof(bool), typeof(RoundEffect), true, propertyChanged: PropertyChanged);

For more info, you can refer to Attached Properties.

Best Regards,
Kyle Wang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.