Scrolling Issue on Tabbed Page in iOS When Adding Dynamic Labels

Omkar Pawar 255 Reputation points
2025-06-17T06:05:47.6133333+00:00

I am experiencing a scrolling issue on a tabbed page in iOS when dynamically adding labels. In most cases (approximately 8 out of 10 times), I am unable to scroll down after adding the labels. This issue occurs on both real and simulator devices.

workload

Sample code : - https://github.com/user-attachments/files/20237370/ScrollIssueOnTabbedPage-master.zip

  • Run the attached project.
  • After the app launches, click on the "Add Label" button.
  • Continue clicking "Add Label" until the screen is full.
  • Wait for 1-2 seconds.
  • Click the "Add Label" button again.
  • Attempt to scroll down after labels have been added.
Developer technologies | .NET | .NET MAUI
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Le (WICLOUD CORPORATION) 995 Reputation points Microsoft External Staff
    2025-07-24T09:05:47.27+00:00

    Hello,

    iOS may not recalculate the layout properly after dynamic changes, especially when the UI thread is briefly idle or the layout pass is skipped.

    To resolve this, please try forcing a layout refresh after adding each label. This ensures the scroll view recalculates its content size properly.

    Steps to implement:

    1. Modify your OnAddLabelTab1 and OnAddLabelTab2 methods to include layout refresh logic.
    2. Use Device.BeginInvokeOnMainThread to ensure UI updates occur on the main thread.
    public partial class TabbedPageDemo : TabbedPage
    {
        public TabbedPageDemo()
        {
            InitializeComponent();
        }
     
        private int labelCounterTab1 = 10;
        private int labelCounterTab2 = 10;
     
        private void OnAddLabelTab1(object sender, EventArgs e)
        {
            Tab1Stack.Children.Add(new Label { Text = $"New Label {labelCounterTab1} in Tab 1", FontSize = 20 });
            labelCounterTab1++;
     
            Device.BeginInvokeOnMainThread(() =>
            {
                Tab1Stack.ForceLayout();
                Tab1Scroll.ForceLayout(); // Ensure you name your ScrollView as Tab1Scroll in XAML
            });
        }
     
        private void OnAddLabelTab2(object sender, EventArgs e)
        {
            Tab2Stack.Children.Add(new Label { Text = $"New Label {labelCounterTab2} in Tab 2", FontSize = 20 });
            labelCounterTab2++;
     
            Device.BeginInvokeOnMainThread(() =>
            {
                Tab2Stack.ForceLayout();
                Tab2Scroll.ForceLayout(); // Ensure you name your ScrollView as Tab2Scroll in XAML
            });
        }
    }
    

    If the issue persists, consider adding a short delay before forcing layout:

      await Task.Delay(50);
    

    I hope this helps resolve the issue.

    References:


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.