首页 > 解决方案 > 未找到“HeightRequest”的属性、BindableProperty 或事件,或者 Xamarin.Forms 中的值和属性错误之间的类型不匹配

问题描述

不是Xamarin Forms 的副本 没有为“Sku”找到属性、可绑定属性或事件,或者值和属性之间的类型不匹配

我对 Xamarin.Forms 完全陌生,正在尝试我的第一个Hello World应用程序。
我写了以下代码:

<?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>

但是,我收到错误

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

我哪里错了?

标签: xamarin.formscompiler-errors

解决方案


我基本上想要做的是将标签的高度设置为渲染设备高度的5%

好的,所以如果这只是您关心的问题,请像这样使用它:

<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>

您面临的异常是由于语法错误。你必须用RelativeLayout而不是 StackLayout替换你的父布局


推荐阅读