No property, BindableProperty, or event found for “HeightRequest”, or mismatching type between value and property error in Xamarin.Forms

旧街凉风 提交于 2021-01-06 03:30:54

问题


Not a duplicate of Xamarin Forms No property, bindable property, or event found for 'Sku', or mismatching type between value and property

I am completely new to Xamarin.Forms and am trying my first Hello World app.
I wrote the following code:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="hello_world.MainPage">
    <StackLayout>
        <Label 
            Text="Welome" 
            BackgroundColor="Yellow" 
            TextColor="Green" 
            HeightRequest="{ConstraintExpression Type=RelativeToView, Factor=0.05, Constant=0}"
            FontSize="Medium" />
    </StackLayout>

</ContentPage>

However, I am receiving the error

No property, BindableProperty, or event found for "HeightRequest", or mismatching type between value and property.

Where am I going wrong?


回答1:


You are putting Label inside StackLayout, while the value you use like {ConstraintExpression Type=RelativeToView, Factor=0.05, Constant=0} is using for relativelayout.

These are two different layouts and you can't mix them. Read the document and check the examples there to learn how to use them.

Feel free to ask me any question if you have:).

Update code:

<RelativeLayout>
    <Label 
        Text="Welome" 
        BackgroundColor="Yellow" 
        TextColor="Green" 
        FontSize="Medium"

        RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"

        RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToView, Factor=0.05,Property= Height, Constant=0}"
         />
</RelativeLayout>



回答2:


What I basically want to do is to set the height of the label to 5% of the rendering device's height

Ok, so if this is only your concern then use it like this:

<RelativeLayout>
    <Label 
        Text="Welome" 
        BackgroundColor="Yellow" 
        TextColor="Green"
        RelativeLayout.HeightConstraint="{ConstraintExpression RelativeToParent,Property=Height,Factor=0.05,Constant=0}"
        RelativeLayout.WidthConstraint="{ConstraintExpression RelativeToParent,Property=Height,Factor=0.05,Constant=0}"
        FontSize="Medium" />
</RelativeLayout>

The exception you are facing is because of wrong syntax. And you have to replace your parent layout with RelativeLayout instead of StackLayout




回答3:


Beg your pardon HeightRequest is a bindable property. Your case is "mismatching type between value and property", it can only be double, you cannot bind it to a ConstraintExpression.



来源:https://stackoverflow.com/questions/64003252/no-property-bindableproperty-or-event-found-for-heightrequest-or-mismatchin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!