Maui android scroll view orientation change not consistent

Haviv Elbsz 786 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.
1,399 questions
{count} votes