user20694704
user20694704

Reputation: 51

MAUI set Grid length

I am working on migrating xamarin forms application to .net MAUI.

i am setting the GridLength based on the device height. For this created OnSize class.

below is the code.




public class OnSize<T>
    {
        /// <summary>
        /// The value for a tiny phone, equivalent to an iPhone 4S
        /// </summary>
        public T Tiny { get; set; }

        /// <summary>
        /// The value for a tiny phone, equivalent to an iPhone SE
        /// </summary>
        public T Small { get; set; }

        /// <summary>
        /// The value for a tiny phone, equivalent to an iPhone 8
        /// </summary>
        public T Medium { get; set; }

        /// <summary>
        /// The value for a tiny phone, equivalent to an iPhone 8 Plus or iPhone X
        /// </summary>
        public T Large { get; set; }

        public static implicit operator T(OnSize<T> onSize)
        {
            if(height < 500)
            {
                return onSize.Tiny;
            }

            if(height < 620)
            {
                return onSize.Small;
            }

            if(height < 700)
            {
                return onSize.Medium;
            }

            return onSize.Large;
        }

        static double height => App.Current.MainPage.Height;
    }

using like below

<Grid RowSpacing="1" VerticalOptions="FillAndExpand">
        <Grid.RowDefinitions>
            <RowDefinition>
                <RowDefinition.Height>
                    <OnSize x:TypeArguments="GridLength" Tiny="255" Small="255" Medium="275" Large="317" />
                </RowDefinition.Height>
            </RowDefinition>
</Grid>

Getting below error: Error XFC0009: No property, BindableProperty, or event found for "Tiny", or mismatching type between value and property. (XFC0009)

It is working in Xamarin forms, giving error in MAUI.

Upvotes: 0

Views: 450

Answers (1)

Jianwei Sun - MSFT
Jianwei Sun - MSFT

Reputation: 4332

I reproduced your question by your code. According to the error:

Error XFC0009: No property, BindableProperty, or event found for "Tiny", or mismatching type between value and property.

I try to modify OnSize class to this:

public class OnSize<T> : BindableObject
{
    /// <summary>
    /// The value for a tiny phone, equivalent to an iPhone 4S
    /// </summary>
    //public T Tiny { get; set; }

    public static readonly BindableProperty TinyProperty = BindableProperty.Create(nameof(Tiny), typeof(T), typeof(OnSize<T>));

    public T Tiny
    {
        get => (T)GetValue(OnSize<T>.TinyProperty);
        set => SetValue(OnSize<T>.TinyProperty, value);
    }
....

However the error still still exists. If remove Tiny and other property:

<OnSize x:TypeArguments="GridLength" />

It will work well with no error. Of course this is meaningless.

Finally I find a similar issue on GitHub: XamlC: IValueConverter with generic arguments cannot process GridLength. You can follow it up to see any updates.

Upvotes: 0

Related Questions