Sub-class Entry and Adding DependencyProperty / BindableProperty gives Xaml parse exception

codenutzcodenutz GBMember
edited December 2014 in Xamarin.Forms

Hi all,

I've just been trying to subclass Entry and add a dependency property on it, but I always get a xaml parse exception saying the property does not exist. I've tried several ways to add the property, such as:

public static readonly BindableProperty MaxLengthProperty = BindableProperty.Create<DigitEntry, int?>(c => c.MaxLength, null);

public int? MaxLength
{
    get
    {
        return (int?)GetValue(MaxLengthProperty);
    }
    set
    {
        SetValue(MaxLengthProperty, value);
    }
}

and

public static readonly BindableProperty MaxLengthProperty = BindableProperty.Create("MaxLength", typeof(int?), typeof(DigitEntry), (object)null, BindingMode.OneWay, (BindableProperty.ValidateValueDelegate)null, (BindableProperty.BindingPropertyChangedDelegate)null, (BindableProperty.BindingPropertyChangingDelegate)null, (BindableProperty.CoerceValueDelegate)null, (BindableProperty.CreateDefaultValueDelegate)null);


    public int? MaxLength
    {
        get
        {
            return (int?)this.GetValue(DigitEntry.MaxLengthProperty);
        }
        set
        {
            this.SetValue(DigitEntry.MaxLengthProperty, (object)value);
        }
    }

But both give the same error:

Xamarin.Forms.Xaml.XamlParseException: Position 58:14. No Property of name MaxLength found

The xaml which I'm using looks like this:

<Controls:DigitEntry Grid.Row="4"
        Grid.Column="0"
        Grid.ColumnSpan="2" 
        MaxLength="2"
        Placeholder="Volume" />

Any ideas?

Posts

  • LuckyDayLuckyDay USMember ✭✭✭
    edited December 2014

    Yep, I never spent the time to look into the root cause, but it's due to using a nullable. FWIW I have a MaxLength attached property and using int.MaxValue for a default value works fine as an alternative to the nullable :)

  • codenutzcodenutz GBMember

    Brilliant, thank you! I can work with that.

    FYI - I also tried with a non-nullable Int64 and that also did not work.

  • LuckyDayLuckyDay USMember ✭✭✭

    One of the other things I've found in XF1.3 is that the type converters don't work as well. I was trying to bind some double values to a float BindableProperty. Worked in 1.2.x and started failing in 1.3.

    I've come to understand that exception text to mean a few different things. Most of the time the problem is #1
    1) Binding engine can't convert the value you set to the value type of the Property.
    2) Property doesn't exist.
    3) BindableProperty is not public.

Sign In or Register to comment.