Nella versione attuale di .Net Maui è presente uno strano bug. Si verifica su Android e quando si scorre un layout a pila. La prima volta funziona benissimo, ma la seconda volta la pagina rimane semplicemente vuota. È meglio utilizzare una griglia.
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;
namespace MyApp
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
// Create the ScrollView
var scrollView = new ScrollView();
// Create the StackLayout
var stackLayout = new StackLayout();
// Add some content to the StackLayout
for (int i = 1; i <= 20; i++)
{
var label = new Label
{
Text = $"Item {i}",
FontSize = 20,
HorizontalOptions = LayoutOptions.Center
};
stackLayout.Children.Add(label);
}
// Set the StackLayout as the content of the ScrollView
scrollView.Content = stackLayout;
// Set the ScrollView as the content of the page
Content = scrollView;
}
}
}