BindableProperty - BindableProperty.Create obsolete - updating to new method

rakeshFrakeshF USMember ✭✭
edited February 2017 in Xamarin.Forms

I am trying to update a RoundBoxView that was demo'd in Xamarin University which has an obsolete declaration. I have tried to update it with what I think is correct, but I am getting a System.TypeInitializationException error. Any ideas?

This is the current working version which is obsolete and Xamarin are removing soon..
public static readonly BindableProperty CornerRadiusProperty =BindableProperty.Create<RoundedBoxView, double>(p => p.CornerRadius, 0);

I have changed it to the following:
public static readonly BindableProperty CornerRadiusProperty = BindableProperty.Create(nameof(CornerRadius), typeof(double), typeof(RoundedBoxView),0);

Here is the property for CornerRadius:
public double CornerRadius
{
get { return (double)GetValue(CornerRadiusProperty); }
set { SetValue(CornerRadiusProperty, value); }
}

Full code:

//

 public class RoundedBoxView : BoxView
{
   //works
   public static readonly BindableProperty CornerRadiusProperty =BindableProperty.Create<RoundedBoxView, double>(p => p.CornerRadius, 0);

 //does not work
 //   public static readonly BindableProperty CornerRadiusProperty = BindableProperty.Create(nameof(CornerRadius), typeof(double), typeof(RoundedBoxView),0);


    public double CornerRadius
    {
        get { return (double)GetValue(CornerRadiusProperty); }
        set { SetValue(CornerRadiusProperty, value); }
    }
  }

Posts

  • rakeshFrakeshF USMember ✭✭

    @JohnHardman said:
    @rakeshF - Try:

        public static readonly BindableProperty CornerRadiusProperty =
                    BindableProperty.Create(
                        nameof(CornerRadius), 
                        typeof(double), 
                        typeof(RoundedBoxView), 
                        default(double));
    

    The only difference is that this will use 0.0 for the final parameter.

    Thank you that worked.

Sign In or Register to comment.