How to define an constructor argument accessible from Xaml

前端 未结 1 959
我寻月下人不归
我寻月下人不归 2021-01-15 22:48

Xamarin\'s ListView defines a 1-argument constructor as follows:

public ListView([Parameter(\"CachingStrategy\")] ListViewCachingStrategy cachin         


        
1条回答
  •  梦谈多话
    2021-01-15 23:09

    To make things simpler, I would recommend creating a BindableProperty for IsReadOnly. But you can always use x:Arguments to pass in parameters to constructor:

    
        
            true
        
    
    

    EDIT - 1

    There is one hack that you can use - (I wouldn't recommend as this could change anytime with an update in XAMLC compilation) - but you can make sure to keep the namespace same as the one used internally while defining the parameter attribute.

    namespace Xamarin.Forms
    {
        [AttributeUsage(AttributeTargets.Parameter)]
        internal sealed class ParameterAttribute : Attribute
        {
            public ParameterAttribute(string name)
            {
                Name = name;
            }
    
            public string Name { get; }
        }
    }
    

    And XAML usage would look like:

    
    

    EDIT - 2 This hack only seems to work if XAMLCompilation is applied to host control/page.

    0 讨论(0)
提交回复
热议问题