我正在创建一个财务应用,需要显示包含节标题和多个网格的表格。
在附带的截图中,我几乎就在那里。我需要第一列左对齐(开始),行需要大约是默认高度的两倍。
var content = new TableView
{
Intent = TableIntent.Data,
Root = new TableRoot("Performance"),
BackgroundColor = Color.Green
};
content.Root.Add(GetTableSection("Monthly", Model.Monthly);
.................
private TableSection GetTableSection(string title, List<PerformanceRow> performanceRows)
{
TableSection section = new TableSection()
{
Title = title
};
foreach (var row in performanceRows)
{
Grid grid = new Grid
{
VerticalOptions = LayoutOptions.FillAndExpand,
HeightRequest = 100, //?????????
BackgroundColor = Color.Red,
ColumnDefinitions =
{
new ColumnDefinition {Width = new GridLength(.3, GridUnitType.Star)},
new ColumnDefinition {Width = new GridLength(.3, GridUnitType.Star)},
new ColumnDefinition {Width = new GridLength(.3, GridUnitType.Star)},
}
};
//First Row
grid.Children.Add(new Label {Text = row.Title, HorizontalOptions = LayoutOptions.Start}, 1, 0);
grid.Children.Add(new Label {Text = "Market Value"}, 2, 0);
grid.Children.Add(new Label {Text = row.MarketValue.ToString("C"), HorizontalOptions = LayoutOptions.End}, 3, 0);
//Second Row
grid.Children.Add(new Label {Text = " "}, 1, 1);
grid.Children.Add(new Label {Text = "Return"}, 2, 1);
grid.Children.Add(new Label {Text = row.ReturnRate.ToString("C"), HorizontalOptions = LayoutOptions.End}, 3, 1);
section.Add(new ViewCell()
{
View = grid,
Height = 100 //??????????
});
}
return section;
}
答案 0 :(得分:0)
这有效:
为表视图设置UnevenRows为true,然后将表意图设置为行