IOS ScrollView add children views ,bottom button will out of screen,then scroll back to screen, but button will not work?

Fei Xu 490 Reputation points
2023-06-03T15:55:43.8833333+00:00

ScrollView add some children views, btnTest will move out the screen, then scroll back to screen, but btnTest will not work ?

Android is OK.

VS17.7.0 .Net7.0 IOS16.4

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiApp1.ScrollViewTest"
             Title="ScrollViewTest">
    <ScrollView>
    <StackLayout>
            <Button x:Name="btnAdd" Text="AddItems" Clicked="btnAdd_Clicked"/>
            <StackLayout x:Name="sl">
            <Label 
            Text="Welcome to .NET MAUI!"
            VerticalOptions="Center" 
            HorizontalOptions="Center" />
            </StackLayout>
            <Button x:Name="btnTest" Text="ButtonTest" Clicked="btnTest_Clicked"/>
        </StackLayout>
    </ScrollView>
</ContentPage>



public partial class ScrollViewTest : ContentPage
{
	public ScrollViewTest()
	{
		InitializeComponent();
	}

   
    private void btnAdd_Clicked(object sender, EventArgs e)
    {
        for(int i = 0; i < 20; i++) 
        {
            Label lbl = new Label();
            lbl.HeightRequest = 50;
            lbl.Text = "Welcome to .NET MAUI!";
            sl.Add(lbl);
        }
    }

    private void btnTest_Clicked(object sender, EventArgs e)
    {
        DisplayAlert("tips", "I'm alive", "OK");
    }
}
Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    2023-06-05T07:22:38.83+00:00

    Hello,

    There is a known issue reported at GitHub- Buttons offscreen inside ScrollView do not work on iOS, please follow the progress at GitHub.

    And you could try the solution:

     <ScrollView x:Name="Scroll" >
      ....
      </ScrollView>
    

    Hiding and reshowing the ScrollView.

    private void btnAdd_Clicked(object sender, EventArgs e)
    {
                    ...
                    Scroll.IsVisible = false;
                    Scroll.IsVisible = true;
    }
    

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.