简体   繁体   English

使用Xamarin.Forms制作无法编辑的表

[英]Making an uneditable table with Xamarin.Forms

I'm in the process of converting an Android app I made over to Xamarin.Forms for use in iOS and Windows Phone. 我正在将制作的Android应用程序转换为Xamarin.Forms,以便在iOS和Windows Phone中使用。

What I'm trying to do: 我正在尝试做的是:

在此处输入图片说明

I want to make a simple 2 column wide table. 我想做一个简单的2栏宽的表格。 I followed this guide however the entry cells were editable with no property to turn it off, I also need to be able to modify these entries easily (through code). 我遵循了本指南,但是条目单元格是可编辑的,没有属性可以将其关闭,我还需要能够轻松地(通过代码)修改这些条目。

What I currently have: 我目前所拥有的:

var section = new TableSection() { 
    new EntryCell  { Label = "Chest", Text = "0" },
};

TableView tableView = new TableView
        {
            IsEnabled = false,
            Root = new TableRoot
            {
                section
            }
        };

EDIT: Already tried a TextCell, same deal, check this screenshot out 编辑:已经尝试了TextCell,同样的操作,签出此屏幕截图

在此处输入图片说明

Also adds a bunch of random lines after my textentry 在我的textentry之后还添加了一堆随机行

在此处输入图片说明

In a perfect world, I'd like something similar to an HTML table. 在理想的世界中,我想要类似于HTML表的内容。

I saw a different thread where someone suggested a listview, but I don't see how I could make a table with that. 我看到了有人在其中建议列表视图的另一个线程,但是我看不到如何用该列表创建表。

I tried many different setups with a Grid, but it doesn't seem to be working 我用Grid尝试了许多不同的设置,但似乎没有用

        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);

I'm not marking this as the accepted answer for a few days in case someone has a better solution. 如果有人有更好的解决方案,几天来我就不会将其标记为可接受的答案。 I'm open to suggestions, since if I had to add another column to this "table", this solution wouldn't work. 我乐于接受建议,因为如果必须在此“表”中添加另一列,则此解决方案将行不通。

As of this date (June 11th, 2016), I have to say that TableView is too buggy to be practical. 截至该日期(2016年6月11日),我不得不说TableView的bug太大了,无法实用。 There's a consistent complaints of extra spaces, also when you touch the textviews, they look like they're about to perform an action (hard to explain without a video). 人们一直在抱怨多余的空间,当您触摸文本视图时,它们看起来就像是要执行一项操作(没有视频就很难解释)。 They're static text, they shouldn't respond to touch. 它们是静态文本,不应响应触摸。

Here is how I made my simple two column table (although it's more like a tabular view than a conventional table). 这是我制作简单的两列表的方式(尽管它比常规表更像表格视图)。 Cliffnotes? 悬崖音符? Several horizontally oriented StackLayouts inside one vertical oriented StackLayout. 一个垂直定向StackLayout内的几个水平定向StackLayouts。 I position one Label on the far left, and the other on the far right. 我将一个Label放置在最左边,将另一个放置在最右边。 End result looks something like this: 最终结果如下所示: 在此处输入图片说明

    //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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM