Hello,
Welcome to our Microsoft Q&A platform!
Do you want to achieve the result like following screenshot with CollectionView
Here is my layout.
<CollectionView ItemsSource="{Binding Monkeys}"
>
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical"
Span="9">
</GridItemsLayout>
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout>
<Button Text="{Binding Name}"></Button>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
layout background code.
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
this.BindingContext = new MyViewModel();
}
}
Here is my MyViewModel.cs
public class MyViewModel
{
public ObservableCollection<Monkey> Monkeys { get; set; }
public MyViewModel()
{
Monkeys = new ObservableCollection<Monkey>();
for (int i = 1; i < 82; i++)
{
Monkeys.Add(new Monkey { Name=i.ToString() });
}
}
}
public class Monkey
{
public string Name { get; set; }
}
Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
You can add Letter or Number to the every button by
Monkeys.Add(new Monkey { Name="test1" });
inMyViewModel.cs
. I usedfor (int i = 1; i < 82; i++)
for testing, you can add it one by one