[英]a dynamic list in a GridView in Xamarin.Forms
I need to do a GridView that receives a list that I don't know and shows it. 我需要做一个GridView来接收一个我不知道的列表并显示出来。 How can I do that in xamarin forms? 如何以xamarin形式进行处理? I need that the layout be repeted like I want, like a template in ListView...In ListView I know How do that but in Grid I don't. 我需要像我想要的那样重复布局,就像ListView中的模板...在ListView中,我知道该怎么做,但是在Grid中,我不知道。 Isn't there a way to set a ListView appearance to Grid the data? 有没有办法设置ListView外观以对数据进行网格化? I won't know how many rows and columns it will have, because it dependes of the data quantity. 我不知道它将有多少行和列,因为它取决于数据量。
My code behind is: 我背后的代码是:
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class CategoriasView : ContentPage
{
List<Categorias> lstCategorias;
public CategoriasView()
{
InitializeComponent();
CallingCategoriasAsync();
}
void eteste()
{
int row = 0;
int column = 0;
foreach (var item in lstCategorias)
{
gridteste.Children.Add(new Label { Text = item.nome }, row, column);
if (column == 0)
{
column = 1;
}
else
{
column = 0;
row++;
}
}
var i = 0;
}
async Task CallingCategoriasAsync()
{
lstCategorias = await Webservice.GetCategoriasAsync("1242");
eteste();
}
}
} }
My XAML is: 我的XAML是:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="neoFly_Montana.Views.CategoriasView">
<ContentPage.Content>
<StackLayout>
<Grid x:Name="gridteste">
</Grid>
</StackLayout>
</ContentPage.Content>
The behind was working when I debbuged it, but nothing is shown on the screen...I think I need to put somenthing in code... 当我对它进行调试时,后面的东西正在工作,但是屏幕上什么都没有显示……我想我需要在代码中添加一些东西……
//Creting a Dynamic Lable //创建动态标签
Label lbl_new = new Label();
lbl_new.Text="LablelText";
//assigning Row and column Position //分配行和列的位置
Grid.SetRow(lbl_new , RowNo);
Grid.SetColumn(lbl_new , ColNo);
//Assigning Control to Grid //将控件分配给网格
gridteste.Children.Add(lbl_new);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.