ScrollView进入ContentPage推送异步不起作用

时间:2017-03-08 15:05:52

标签: ios asynchronous xamarin.forms scrollview

我需要你的帮助。我实际上从Xamarin.forms开始。 我有一个HomePage:TabbedPage,它有3个ContentPage。

这三个页面中的一个是ListView,在项目上点击,使用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
};

我在这个新页面上有一个ScrollView,但它不起作用。

我复制了页面并在没有Navigation.PushAsync的情况下调用了它,并且滚动了WORKS。

我实际上只使用iOS模拟器。

你知道原因吗?

我正在使用xaml。

非常感谢。如果您需要更多信息,请告诉我..!

有我的App.xaml.cs

public App()
    {
        InitializeComponent();

        MainPage = new 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);
     }
 }

我的主页调用GameListPage:

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

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

有事件:

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

游戏页面在这里:

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>

我实际上把这个内容用于测试滚动。并且,在另一个内容页面中,具有相同的内容,我可以滚动。它就在这个页面上,用异步Navigation.PushAsync ...

调用

编辑:使用带有HeightRequest的StackLayout解决为1500.我的滚动工作现在......暂时解决了..它不正确

1 个答案:

答案 0 :(得分:0)

我建议您为您的观点设置BackgroundColor,如:

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

因此,您可以仔细检查您的视图实际上是否为ContentPage本身的渲染器。

另一个问题可能是你没有足够的元素(Label, Image, Entry, Button ......无论如何:https://developer.xamarin.com/guides/xamarin-forms/user-interface/controls/views/)在你的ScrollView上实际滚动。

为您的观点设置测试背景颜色,并告诉我们实际问题是什么。

另请注意,ScrollView具有Content属性,因此您可以为其添加布局。例如:

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