我有一个网格,我在其中添加了 moreTileView。但它只是在第一行和第一列呈现(相互重叠)。我想要的是在新行和/或新列中呈现每个新的“图块”。也许这不是最好的方法。如果你们有一个击球手想法如何实现我想要做的事情,请告诉我。
MoreTilePage.xaml
<ContentPage.Content>
<ScrollView>
<StackLayout x:Name="MoreTileViewHolder" />
<ScrollView>
</ContentPage.Content>
MoreTilePage.xaml.cs
public partial class MoreTilePage : ContentPage
{
public MoreTilePage()
{
InitializeComponent();
var items = PixelApp.Platform.AppContext.Instance.moreViewModel?.Items;
Grid myGrid = new Grid();
myGrid.HorizontalOptions = LayoutOptions.FillAndExpand;
myGrid.Padding = new Thickness(10);
myGrid.RowDefinitions = new RowDefinitionCollection
{
new RowDefinition { Height = new GridLength(220) },
new RowDefinition { Height = new GridLength(220) },
new RowDefinition { Height = new GridLength(220) },
new RowDefinition { Height = new GridLength(220) },
new RowDefinition { Height = new GridLength(220) }
};
myGrid.ColumnDefinitions = new ColumnDefinitionCollection
{
new ColumnDefinition { Width = GridLength.Star },
new ColumnDefinition { Width = GridLength.Star }
};
int iColumn = 0;
int iRow = 0;
int iItem = 1;
foreach (MoreModel model in items)
{
if (iItem > 2)
{
iItem = 1;
iRow++;
}
model.row = iRow;
model.column = iColumn;
var tile = new MoreTileView(model);
myGrid.Children.Add(tile);
iItem++;
if (iColumn == 0)
iColumn = 1;
else
iColumn = 0;
}
MoreTileViewHolder.Children.Add(myGrid);
}
}
这是执行时的输出
然而,这就是我想要的样子
元芳怎么了
杨__羊羊
相关分类