c# - 更改列表视图的高度
问题描述
所以我ListView
在一个里面有 3 个,StackLayout
但我得到了一个卷轴,ListView
我希望它们的高度取决于包含的项目数量。
这是我的xaml
文件
<StackLayout>
<StackLayout>
<Label Text="Ingredientes"
HorizontalOptions="CenterAndExpand">
</Label>
<ListView x:Name="listaIngredientes"
ItemsSource="{Binding ingredientes}"
VerticalOptions="FillAndExpand">
</ListView>
</StackLayout>
<StackLayout>
<Label Text="Informacion dietetica"
HorizontalOptions="CenterAndExpand">
</Label>
<ListView x:Name="informacionDietetica"
ItemsSource="{Binding especificacionesDieteticas}"
VerticalOptions="FillAndExpand">
</ListView>
</StackLayout>
<StackLayout>
<Label Text="Informacion nutricional"
HorizontalOptions="CenterAndExpand">
</Label>
<ListView x:Name="informacionNutricional"
ItemsSource="{Binding especificacionesSanitarias}"
VerticalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding}">
</TextCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</StackLayout>
我试过把所有东西都包在里面ScrollView
,AbsoluteLayout
但RelativeLayout
没有人成功。
解决方案
这里有一个解决方案,你可以试一试。
如果可以确定其中的数量并设置每个的高度,则Cells
可以计算出的高度。同时,程序运行时可以如下动态修改高度。ListView
Cell
ListView
ListView
listview.HeightRequest = CellCount * CellHeight;
例如:列表视图的高度listaIngredientes
应该是:
listaIngredientes.HeightRequest == YourViewModel.ingredientes.Count * CellHeight;
推荐阅读
- flutter - 使用 ImagePicker 上传图片
- r - R Shiny - 如何在一个会话中同时执行多项任务?如两次计算或两次定时器
- oracle - 数据库作业调度器时间限制
- python - AMQP 1.0 消息发送困难
- python - 如何在 docker 中运行 python 脚本并在本地保存结果?
- javascript - React 组件未显示正确的渲染计数
- python - Python Tkinter:循环运行时窗口冻结
- amazon-web-services - 使用代入的 IAM 角色从 EKS pod 访问远程 EKS 集群
- javascript - 剑道ui删除数字过滤器微调器
- javascript - Node JS Socket.IO 和 HTTP 请求