我需要您的帮助。我实际上是从xamarin.forms开始的。我有一个主页:包含3个ContentPage的TabBedPage。
这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,但它不起作用。
我复制了该页面,并在没有avavigation.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.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>
我实际上放了这些内容来测试滚动。而且,在一个彼此的内容页面中,我可以滚动。它只是在此页面上,该页面与async navigation.pushasync ...
调用编辑:用heightrequest的堆叠式求解到1500。我现在的滚动作品..临时解决了。
我建议您将BackgroundColor
设置为:
ScrollView mainContainer = new ScrollView{
BackgroundColor = Color.Red
};
因此,您可以仔细检查您的视图是否正在渲染到ContentPage
本身。
另一个问题也可能是您没有足够的元素( Label, Image, Entry, Button
... whitch:https://developer.xamarin.com/guides/guides/xamarin-forms/user-interface/controls/views/)滚动浏览到实际滚动。
为您的视图设置测试背景颜色,让我们知道实际上是什么。
还请记住,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 }
};