xamarin.forms - 为 Xamarin TableView 中的每个 EntryCell 设置相同的标签宽度
问题描述
我正在学习如何<TableView>
在 Xamarin Forms 中使用,我写了这个:
<TableView Intent="Form">
<TableRoot>
<TableSection Title="Random values">
<EntryCell Label="A beautiful first number" Placeholder="1" Keyboard="Numeric"/>
<EntryCell Label="2nd num" Placeholder="2" Keyboard="Numeric"/>
</TableSection>
</TableRoot>
</TableView>
如何为每个设置相同的宽度<entry cell>
?我不希望输入部分从不同的水平位置开始。
解决方案
据我所知,Custom Cell将是实现这一目标的不错选择。因为Entry Cell
没有设置Width
的属性Label
。
使用 View Cell 可以包含布局以满足您的需求,如下所示:
<TableView Intent="Form" >
<TableRoot>
<TableSection Title="Random values">
<EntryCell Label="A beautiful first number"
Placeholder="1 Entry Cell"
Keyboard="Numeric" />
<EntryCell Label="2nd num"
Placeholder="2 Entry Cell"
Keyboard="Numeric" />
<ViewCell>
<StackLayout Orientation="Horizontal"
Padding="2">
<Label Text="A beautiful first number"
WidthRequest="150"
Margin="5,0,0,0"
VerticalOptions="CenterAndExpand"/>
<Entry Placeholder="1 View Cell" WidthRequest="250"/>
</StackLayout>
</ViewCell>
<ViewCell>
<StackLayout Orientation="Horizontal" Padding="2" >
<Label Text="2nd num"
WidthRequest="150"
Margin="5,0,0,0"
VerticalOptions="CenterAndExpand" />
<Entry Placeholder="2 View Cell"
WidthRequest="250" />
</StackLayout>
</ViewCell>
</TableSection>
</TableRoot>
</TableView>
效果:
推荐阅读
- c++ - 如何在对话框中托管预览处理程序
- oauth-2.0 - 当用户需要先登录以确定要请求的范围时,如何请求适当范围的访问令牌?
- python - Python如何获取每个集群中的最大数量
- c - 为什么printf继续读取并显示下一个整数变量的值时会得到这个值
- python - 如何从 plyer.notification 中删除“Python”一词?
- flutter - 如何在 Flutter 中初始化 StatefulWidget 的 State 中的字段?
- javascript - 提供投影对象时键入 mongoose findOne 查询
- python - Pandas 按列值过滤
- c++ - DllMain 是否应该被命名为另一个名字?
- python-3.x - Python 使用 MagicMock 在 Pytest 测试中模拟两个函数