我有一个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 =&#34; True&#34;但这似乎没有效果。
是否可以更改我添加的最后一个ViewCell(类型TableViewFooter)的高度?
答案 0 :(得分:1)
尝试此解决方法:
public TableViewFooter(string text, double height)
{
InitializeComponent();
_commentLbl.Text = text;
Height = height;
}
并在ViewCell的XMAL中的Grid中删除此行:
VerticalOptions="CenterAndExpand"