我正在将我制作的Android应用转换为Xamarin.Forms,以便在iOS和Windows Phone中使用。
我想做的事情:
我想制作一个简单的2列宽表。我跟着this guide但是条目单元格是可编辑的,没有属性可以将其关闭,我还需要能够轻松地修改这些条目(通过代码)。
我现在有什么:
var section = new TableSection() {
new EntryCell { Label = "Chest", Text = "0" },
};
TableView tableView = new TableView
{
IsEnabled = false,
Root = new TableRoot
{
section
}
};
编辑:已经尝试了TextCell,同样的交易,请查看此屏幕截图
在我的textentry
之后还添加了一堆随机行在一个完美的世界里,我喜欢类似于HTML表格的东西。
我看到一个不同的帖子,有人建议列表视图,但我不知道如何制作一张表。
我尝试使用网格进行了许多不同的设置,但它似乎无法正常工作
Grid grid = new Grid
{
VerticalOptions = LayoutOptions.FillAndExpand,
RowDefinitions =
{
new RowDefinition { Height = new GridLength(100, GridUnitType.Absolute) }
},
ColumnDefinitions =
{
new ColumnDefinition { Width = new GridLength(100, GridUnitType.Absolute) },
new ColumnDefinition { Width = new GridLength(100, GridUnitType.Absolute) }
}
};
grid.Children.Add(txtChest);
grid.Children.Add(txtChestResults);
答案 0 :(得分:0)
如果有人有更好的解决方案,我不会将此标记为几天的公认答案。我愿意接受建议,因为如果我必须在这个“表”中添加另一个列,这个解决方案将不起作用。
截至此日期(2016年6月11日),我不得不说TableView太麻烦而不实用。对于额外空间有一贯的抱怨,当你触摸文本视图时,他们看起来就像要执行一个动作(没有视频很难解释)。它们是静态文本,不应该对触摸做出反应。
这就是我如何制作简单的两列表格(虽然它更像是一个表格视图而不是传统的表格)。 Cliffnotes?在一个垂直方向的StackLayout内部有几个水平方向的StackLayout。我在最左边放置一个标签,在最右边放置另一个标签。最终结果如下所示:
//Result Items
/* Start chest */
Label txtChest = new Label
{
Text = "Chest",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.StartAndExpand
};
Label txtChestResults = new Label
{
Text = "0",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.EndAndExpand
};
/* End chest */
/* Start Biceps */
Label txtBiceps = new Label
{
Text = "Biceps",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.StartAndExpand
};
Label txtBicepsResults = new Label
{
Text = "0",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.EndAndExpand
};
/* End Biceps */
/* Start Forearms */
Label txtForearms = new Label
{
Text = "Forearms",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.StartAndExpand
};
Label txtForearmsResults = new Label
{
Text = "0",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.EndAndExpand
};
/* End Forearms */
/* Start Neck */
Label txtNeck = new Label
{
Text = "Neck",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.StartAndExpand
};
Label txtNeckResults = new Label
{
Text = "0",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.EndAndExpand
};
/* End Neck */
/* Start Thighs */
Label txtThighs = new Label
{
Text = "Thighs",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.StartAndExpand
};
Label txtThighsResults = new Label
{
Text = "0",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.EndAndExpand
};
/* End Thighs */
/* Start Calves */
Label txtCalves = new Label
{
Text = "Calves",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.StartAndExpand
};
Label txtCalvesResults = new Label
{
Text = "0",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.EndAndExpand
};
/* End Calves */
//Chest StackLayout
StackLayout chestLayout = new StackLayout
{
Orientation = StackOrientation.Horizontal
};
chestLayout.Children.Add(txtChest);
chestLayout.Children.Add(txtChestResults);
//biceps layout
StackLayout bicepsLayout = new StackLayout
{
Orientation = StackOrientation.Horizontal
};
bicepsLayout.Children.Add(txtBiceps);
bicepsLayout.Children.Add(txtBicepsResults);
//forearms layout
StackLayout forearmsLayout = new StackLayout
{
Orientation = StackOrientation.Horizontal
};
forearmsLayout.Children.Add(txtForearms);
forearmsLayout.Children.Add(txtForearmsResults);
//Neck layout
StackLayout neckLayout = new StackLayout
{
Orientation = StackOrientation.Horizontal
};
neckLayout.Children.Add(txtNeck);
neckLayout.Children.Add(txtNeckResults);
//Thighs layout
StackLayout thighsLayout = new StackLayout
{
Orientation = StackOrientation.Horizontal
};
thighsLayout.Children.Add(txtThighs);
thighsLayout.Children.Add(txtThighsResults);
//Calves layout
StackLayout calvesLayout = new StackLayout
{
Orientation = StackOrientation.Horizontal
};
calvesLayout.Children.Add(txtCalves);
calvesLayout.Children.Add(txtCalvesResults);
StackLayout resultsLayout = new StackLayout
{
Orientation = StackOrientation.Vertical
};
resultsLayout.Children.Add(chestLayout);
resultsLayout.Children.Add(bicepsLayout);
resultsLayout.Children.Add(forearmsLayout);
resultsLayout.Children.Add(neckLayout);
resultsLayout.Children.Add(thighsLayout);
resultsLayout.Children.Add(calvesLayout);
//add chest results
layout.Children.Add(resultsLayout);