【发布时间】:2018-02-01 23:08:45
【问题描述】:
我有一个 TableView 设置如下:
<ContentPage.Content>
<TableView x:Name="tableView" Intent="Settings" HasUnevenRows="True">
</TableView>
</ContentPage.Content>
我在后端代码中添加了TextCells
var newSection = new TableSection("Choose Categories");
foreach (var category in categories)
{
var cell = new CategoryViewCell
{
BindingContext = category
};
cell.SelectedOrToggled += selectCategory;
newSection.Add(cell);
}
// I want to set the height of TableViewFooter to 200 but
// it does not happen. I just see a row colored red that
// is the same height as all the other rows.
var cmt = new TableViewFooter(
"Select a Category and all cards from that category will be added to the deck",
200);
newSection.Add(cmt);
return newSection;
然后我添加这个 ViewCell 并在 C# 支持代码中添加文本并设置高度。
<ViewCell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Japanese.TableViewFooter">
<Grid
BackgroundColor="Red"
x:Name="_containerGrid"
VerticalOptions="CenterAndExpand"
Padding="20,10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label
x:Name="_commentLbl"
Style="{DynamicResource ListItemDetailTextStyleStyle}"
TextColor="#59595F"
HorizontalOptions="FillAndExpand"
VerticalOptions="CenterAndExpand" />
</Grid>
</ViewCell>
public partial class TableViewFooter : ViewCell
{
public TableViewFooter(string text, double height)
{
InitializeComponent();
_commentLbl.Text = text;
_commentLbl.HeightRequest = height;
_containerGrid.HeightRequest = height;
}
}
但是,无论我做什么,ViewCell(TableViewFooter 类型)的高度仍然与其他行的高度相同。
我尝试设置 HasUnevenRows="True" 但这似乎没有效果。
是否可以更改我添加的最后一个 ViewCell(类型 TableViewFooter)的高度?
【问题讨论】:
-
我想你需要一个渲染器来调整高度,也许看看这里:forums.xamarin.com/discussion/2889/…
-
执行 section.Add(new CustomViewCell { Height = 100 });不工作?
-
我正在尝试将高度设置为 200(第二个参数)但不起作用。
标签: xamarin xamarin.forms