xamarin.forms - 未找到“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.
我哪里错了?
解决方案
我基本上想要做的是将标签的高度设置为渲染设备高度的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替换你的父布局
推荐阅读
- node.js - 根据日期对数据进行分类
- python - ld:在 MacOS 上找不到 -lboost_python 的库
- docker - 如何使用 Grafana Docker 连接 MySQL 到本地 MySQL 服务器
- reactjs - 在 redux 商店中存储授权标志是否安全
- google-app-engine - 具有 python 3.7 标准环境和端点的 Google 应用程序引擎
- neo4j - 删除 Neo4J 中以特定节点开始和结束的所有节点
- android - 如何在活动中包含底部导航视图布局,使其显示在列表视图项下方?
- excel - 使用密码保护工作簿,复制到新目的地
- excel - WorksheetChangeEvents 函数在运行时可能会错过事件吗?
- python - 如何修改 Matplotlib 直方图的输出以创建新的修改直方图(不丢失同步)