.Net Maui Stacklayout und der Scrollviewer

In der aktuellen Version von .Net Maui gibt es einen lustigen Fehler. Dieser tritt bei Android und wenn ein Stacklayout scrollen lassen will. Das funktioniert beim ersten Mal super, jedoch passiert es das beim zweiten Mal die Seite einfach leer bleibt. Am besten ein Grid verwenden.

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

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert




Enter Captcha Here :