Maui android change scrolling at runtime not working

Haviv Elbsz 2,071 Reputation points
2023-05-18T18:50:55.67+00:00

Hello all.

this app tester work when switching at runtime

between horizontal and vertical

but not when switching at runtime

between horizontal and Neither. How to fix that

Thank you

===================================================

<?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
        }
    }
}

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,196 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 71,836 Reputation points Microsoft Vendor
    2023-05-19T05:25:40.5666667+00:00

    Hello,

    Yes, I can reproduce this issue. Please use <StackLayout> to wrap the <ScrollView> like following code. Then ScrollOrientation.Neither; is working.

      <StackLayout>
       <ScrollView x:Name="scrollView" >
            <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="CounterBtn_Clicked"
                    HorizontalOptions="Center" />
           </StackLayout>
        </ScrollView>
       </StackLayout>
    

    Best Regards,

    Leon Lu


    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