Maui android scroll view orientation change not consistent

Haviv Elbsz 1,886 Reputation points
2023-05-23T08:10:32.5+00:00

Hello all. changing scrollview orientation is not consistent and understandable. because in this example it works when changed to vertical but not changed for neither and according to an answer I got here to wrap in a stacklayout it's working for this example but for other project not working. can someone explain a consistent way for changing this orientation. I suspect maui behaviour is not consistent. thank you very much . Very important : note that this app as is work ok but when the button clicked instead of Neither action it do a vertical scroll action while the code not contain a vertical action at all.


<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MAUITestApp.MainPage">
			 
    <ScrollView x:Name="scrollView" Orientation="Horizontal">
        <StackLayout 
            Spacing="25" 
            Padding="30,0" 
            VerticalOptions="Center">

            <Button Text="ChangeOrientation" WidthRequest="200" Clicked="Button_Clicked" HorizontalOptions="Start"/>

            <Image
                Source="dotnet_bot.png"
                SemanticProperties.Description="Cute dot net bot waving hi to you!"
                HeightRequest="800"
                WidthRequest="1000" />
                
            <Label 
                Text="Hello, World!"
                SemanticProperties.HeadingLevel="Level1"
                FontSize="32"
                HorizontalOptions="Center" />
            
            <Label 
                Text="Welcome to .NET Multi-platform App UI"
                SemanticProperties.HeadingLevel="Level2"
                SemanticProperties.Description="Welcome to dot net Multi platform App U I"
                FontSize="18"
                HorizontalOptions="Center" />

            <Button 
                x:Name="CounterBtn"
                Text="Click me"
                SemanticProperties.Hint="Counts the number of times you click"
                Clicked="OnCounterClicked"
                HorizontalOptions="Center" />

        </StackLayout>
    </ScrollView>
 
</ContentPage>



namespace MAUITestApp;

public partial class MainPage : ContentPage
{
	int count = 0;

	public MainPage()
	{
		InitializeComponent();
	}

	private void OnCounterClicked(object sender, EventArgs e)
	{
		count++;

		if (count == 1)
			CounterBtn.Text = $"Clicked {count} time";
		else
			CounterBtn.Text = $"Clicked {count} times";

		SemanticScreenReader.Announce(CounterBtn.Text);
	}

    private void Button_Clicked(object sender, EventArgs e)
    {
		if (this.scrollView.Orientation == ScrollOrientation.Neither) // work for vertical
        {
			this.scrollView.Orientation = ScrollOrientation.Horizontal;
        }
        else
        {
			this.scrollView.Orientation = ScrollOrientation.Neither; // work for vertical
        }
    }
}

Hello all.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,862 questions
{count} votes

Accepted answer
  1. Liqun Shen (Shanghai Wicresoft Co Ltd) 160 Reputation points Microsoft Vendor
    2023-06-02T06:01:00.9933333+00:00

    Hello,

    I can also reproduce this issue. When we set Orientation="Neither" the ScrollView can still scroll vertically while cannot scroll horizontally. I found a similar issue might be related but for Xamarin : ScrollView ScrollOrientation.Neither not working properly. You could also raise an issue for Maui if you want.

    The reason why ScrollView will not scroll if it is in a StackLayout was stated by vsfeedback in this thread : ScrollView Does Not Work When Inside A VerticalStackLayout. That's feature of StackLayout not an inconsistent behavior.

    The issue ScrollView Does Not Work When Inside A VerticalStackLayout you mentioned is probably not the same as this question because switching orientation between horizontal and vertically now works on Android and it is resolved.

    Best Regards,

    Liqun Shen.


    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful