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:
- Modify your
OnAddLabelTab1
andOnAddLabelTab2
methods to include layout refresh logic. - 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: