尽管TableView没有开箱即用的ViewCell
可以做到这一点,但您肯定可以推出自己的实现。显然有一个TextCell,但它不会让你指定字体大小和其他东西。
你可以做这样的事情:
<?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="DemoTableView.TablePage" Title="TableView">
<ContentPage.Content>
<TableView Intent="Settings">
<TableRoot>
<TableSection>
<SwitchCell Text="Personal Hotspot" />
<ViewCell> <!-- Simple text -->
<Label Text="Turn on personal hotspot..." FontSize="Small" ForegroundColor="Gray" />
</ViewCell>
<ViewCell> <!-- More complex cell -->
<StackLayout Orientation="Horizontal>
<Image Source="someicon" />
<StackLayout>
<Label Text="TO CONNECT USING WIFI" FontSize="Large"/>
<Label Text="Something more" FontSize="Small" />
</StackLayout>
</StackLayout>
</ViewCell>
</TableSection>
</TableRoot>
</TableView>
</ContentPage.Content>
</ContentPage>
这仅仅是一个简单的例子写的匆忙,但你的想法。您也可以通过从ViewCell
类继承来以编程方式定义自己的单元格,并在TableView中显示它们。
Here's more关于官方文档定制单元。
编辑:按您的意见,我们需要挖比特到特定于平台的代码,以禁用文本只有细胞的选择。您应该创建一个自定义ViewCell实现与iOS的下列自定义渲染:
[assembly: ExportCell(typeof(YourCell), typeof(YourCellRenderer))]
namespace YourProject.iOS
{
public class YourCellRenderer : ViewCellRenderer
{
public override UITableViewCell GetCell (Cell item, UITableView tv)
{
var cell = base.GetCell (item, tv);
cell.SelectionStyle = UITableViewCellSelectionStyle.None;
return cell;
}
}
}
谢谢,但使用ViewCell有两个缺点:1)我仍然得到轻敲细胞,b)从该分离器的悬停效果上面的SwitchCell会略微缩小,因为如果下面有更多选项,通常情况下会这样。有关如何克服这些问题的任何想法? – Physikbuddha
@Physikbuddha哦,没错,没有想到这一点。我更新了我的答案。虽然不太确定b。 – hankide