2
votes

i need your help. I actually begin with Xamarin.forms. I have a HomePage : TabbedPage, which have 3 ContentPage.

One of those 3 pages is a ListView, which on item tapped, call an another Content Page with a ScrollView.

ListView.ItemTapped += async (o, e) =>
{
    var myList = (ListView)o;
    var newPage = (myList.SelectedItem as Object);
    await Navigation.PushAsync(new Page(Object));
    myList.SelectedItem = null; // de-select the row
};

I have a ScrollView on this new Page, but it doesnt work.

I copied the page and called it without Navigation.PushAsync, and the scroll WORKS.

I actually only use iOS Emulator.

Do you have any idea of the reason ?

I'm using xaml.

Thanks a lot. If you need more informations, tell me..!

There is my App.xaml.cs

public App()
    {
        InitializeComponent();

        MainPage = new HomePage();
    } 

There is my HomePage :

public class HomePage : TabbedPage
{
    public HomePage()
    {
        var profilPage = new NavigationPage(new UserPage());
        profilPage.Title = "Profil";
        profilPage.Icon = "user.png";
        var gameListPage = new NavigationPage(new GameListPage());
        gameListPage.Title = "Jeux";
        gameListPage.Icon = "gamepad.png";
        Children.Add(profilPage);
        Children.Add(gameListPage);
     }
 }

And my homePage call GameListPage :

<ContentPage.Content>
    <ListView x:Name="GameListView">
        <ListView.ItemTemplate>
          <DataTemplate> 
            <TextCell Text="{Binding name}" />

          </DataTemplate>
        </ListView.ItemTemplate>
      </ListView>
</ContentPage.Content>

With event :

GameListView.ItemTapped += async (o, e) =>
        {
            var myList = (ListView)o;
            var game = (myList.SelectedItem as Game);
            await Navigation.PushAsync(new GamePage(game));
            //await DisplayAlert("Tapped", game.name, "OK");
            myList.SelectedItem = null; // de-select the row
        };

And the GamePage is here :

gamePage.xaml

    <ContentPage.Content>
    <ScrollView>
        <RelativeLayout x:Name="RelativeLayout"  HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
            <Grid RelativeLayout.WidthConstraint =
          "{ConstraintExpression Type=RelativeToParent,
                                 Property=Width,
                                 Factor=1,
                                 Constant=0}"
        RelativeLayout.HeightConstraint =
          "{ConstraintExpression Type=RelativeToParent,
                                 Property=Height,
                                 Factor=1,
                                 Constant=0}">
              <Grid.RowDefinitions>
                    <RowDefinition Height="500">
                    </RowDefinition>
                    <RowDefinition Height="500">
                    </RowDefinition>
                    <RowDefinition Height="550">
                    </RowDefinition>
                    <RowDefinition Height="20">
                    </RowDefinition>
                    <RowDefinition Height="300">
                    </RowDefinition>
                    <RowDefinition Height="500">
                    </RowDefinition>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*">
                    </ColumnDefinition>
                    <ColumnDefinition Width="*">
                    </ColumnDefinition>
                    <ColumnDefinition Width="*">
                    </ColumnDefinition>
                </Grid.ColumnDefinitions>
                <Grid.Children>

                    <StackLayout Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3">
                        <BoxView BackgroundColor="Black" HeightRequest="500"></BoxView>
                    </StackLayout>
                    <StackLayout Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3">
                        <BoxView BackgroundColor="Black" HeightRequest="500"></BoxView>
                    </StackLayout>
                    <StackLayout Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3">
                        <BoxView BackgroundColor="Black" HeightRequest="500"></BoxView>
                    </StackLayout>
                </Grid.Children>
         </Grid>
          </RelativeLayout>
    </ScrollView>
</ContentPage.Content>

I putted this content actually to test the scroll. And, in one another contentPage, with the same content, i can scroll. Its just on this page, which is call with async Navigation.PushAsync...

Edited : SOLVED with a StackLayout with HeightRequest to 1500. My scroll work now.. temporary solved so.. Its not proper

1
you should post some code, or better, a little repo on github... Can you post "Page" code or xaml?Alessandro Caliaro
Yeah sure, i'll do it in a few time. I'll set my ListView Code, and my Page's XAML. ThanksMaxime Gdr
I edited it ! it's okMaxime Gdr

1 Answers

0
votes

I suggest you to set a BackgroundColor to your views like:

ScrollView mainContainer = new ScrollView{ BackgroundColor = Color.Red };

So you can double check that actually your view is being renderer to the ContentPage itself.

Also another issue can be that you don't have enough elements (Label, Image, Entry, Button... whatever: https://developer.xamarin.com/guides/xamarin-forms/user-interface/controls/views/) on you ScrollView to actually scroll.

Set a test background color to your views and let us know what is actually the issue.

Also remember that the ScrollView has a Contentproperty so you can add a layout to it. Example:

var stack = new StackLayout();

for (int i = 0; i < 100; i++)
{
    stack.Children.Add(new Button { Text = "Button " + i });
}

MainPage = new ContentPage
{
    Content = new ScrollView { Content = stack }
};