WrapLayout.cs Type 'TDeclarer' does not contain a definition for 'Orientation' error?

JunZhang.3823JunZhang.3823 USMember ✭✭
edited August 2014 in Xamarin.Forms

In WrapLayout.cs(download link: http://bit.ly/xf-custompanel) provided by @CraigDunn‌ :

/// <summary>
/// Orientation (Horizontal or Vertical)
/// </summary>
public StackOrientation Orientation {
    get { return (StackOrientation)GetValue (OrientationProperty); }
    set { SetValue (OrientationProperty, value); } 
}

/// <summary>
/// Backing Storage for the Orientation property
/// </summary>
public static readonly BindableProperty OrientationProperty = 
    BindableProperty.Create<WrapLayout, StackOrientation> (w => w.Orientation, StackOrientation.Vertical, 
        bindingPropertyChanged: (bindable, oldvalue, newvalue) => ((WrapLayout)bindable).OnSizeChanged ());

Error says Type 'TDeclarer' does not contain a definition for 'Orientation', but it does have, which is just above OrientationProperty's definition(first line).
Anyone could help me out? Thank you. Btw, error appears after I upgraded the xamarin.forms package.

Best Answer

  • SKallSKall US ✭✭✭✭
    Accepted Answer

    It seems like the signature has changed and the overloaded method in the example isn't available anymore. You would have to use a method that is available:

        public static readonly BindableProperty OrientationProperty = 
            BindableProperty.Create<WrapLayout, StackOrientation>(
                w => w.Orientation, 
                StackOrientation.Vertical, 
                BindingMode.Default,
                null,
                (bindable, oldvalue, newvalue) => ((WrapLayout)bindable).OnSizeChanged (),
                null,
                null);
    

Answers

  • SKallSKall USMember ✭✭✭✭
    Accepted Answer

    It seems like the signature has changed and the overloaded method in the example isn't available anymore. You would have to use a method that is available:

        public static readonly BindableProperty OrientationProperty = 
            BindableProperty.Create<WrapLayout, StackOrientation>(
                w => w.Orientation, 
                StackOrientation.Vertical, 
                BindingMode.Default,
                null,
                (bindable, oldvalue, newvalue) => ((WrapLayout)bindable).OnSizeChanged (),
                null,
                null);
    
  • JunZhang.3823JunZhang.3823 USMember ✭✭
    edited August 2014

    Thank you @SKall. But I still wanna ask a stupid question, why is your solution compilable, but mine not? I guess it's related to type parameter constraint, but I dont know where exactly, could you please give me some hint?

    This is the create API:

    public static BindableProperty Create<TDeclarer, TPropertyType> (Expression<Func<TDeclarer, TPropertyType>> getter, 
    
    TPropertyType defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay, 
    
    BindableProperty.ValidateValueDelegate<TPropertyType> validateValue = null, 
    
    BindableProperty.BindingPropertyChangedDelegate<TPropertyType> propertyChanged = null, 
    
    BindableProperty.BindingPropertyChangingDelegate<TPropertyType> propertyChanging = null, 
    
    BindableProperty.CoerceValueDelegate<TPropertyType> coerceValue = null) where TDeclarer : BindableObject
    

    Could you please tell me where is the constraint which makes mine not compilable? Thank you :D

  • SKallSKall USMember ✭✭✭✭
    edited August 2014

    It's probably an IDE bug, giving you a wrong error message. It should say something about method not available, "no overload takes xxx". The sample code is trying to call a method with these 3 as the first 3 parameters and such a method does not exist. My guess is it existed on the previous version.

    public static BindableProperty Create<TDeclarer, TPropertyType> (
        Expression<Func<TDeclarer, TPropertyType>> getter, 
        TPropertyType defaultValue, 
        BindableProperty.BindingPropertyChangedDelegate<TPropertyType> propertyChanged = null, 
    
  • JunZhang.3823JunZhang.3823 USMember ✭✭

    Thank you @SKall‌ , you're totally right, in my solution I used name argument "bindingPropertyChanged: " which was existing in the old API, but the new API changed this name argument to "propertyChanged: ". I really appreciate that you help noob like me. I would give 5 likes if I could. Have a great labor day(1st Sept in Canada :D)

Sign In or Register to comment.