【发布时间】:2017-07-29 05:30:30
【问题描述】:
我需要你的帮助。我实际上是从 Xamarin.forms 开始的。 我有一个 HomePage:TabbedPage,它有 3 个 ContentPage。
这 3 个页面中的一个是 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 的情况下调用它,并且滚动工作。
我实际上只使用 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 在这里:
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>
我把这个内容实际上是为了测试滚动。而且,在另一个 contentPage 中,具有相同的内容,我可以滚动。它就在这个页面上,通过 async Navigation.PushAsync 调用...
已编辑:解决了 StackLayout 与 HeightRequest 到 1500。我的滚动工作现在..临时解决所以..它不正确
【问题讨论】:
-
你应该发布一些代码,或者更好的是,在 github 上的一个小仓库......你能发布“页面”代码或 xaml 吗?
-
是的,我会在一段时间内完成。我将设置我的 ListView 代码和我的页面的 XAML。谢谢
-
我编辑了它!没关系
标签: ios asynchronous xamarin.forms scrollview