ios - ScrollView 进入内容页面推送异步不起作用
<p><p>我需要你的帮助。我实际上是从 Xamarin.forms 开始的。
我有一个 HomePage:TabbedPage,它有 3 个 ContentPage。 </p>
<p>这 3 个页面中的一个是 ListView,在点击项目时,它会调用另一个带有 ScrollView 的内容页面。</p>
<pre><code>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
};
</code></pre>
<p>我在这个新页面上有一个 ScrollView,但它不起作用。 </p>
<p>我复制了页面并在没有 Navigation.PushAsync 的情况下调用它,并且滚动工作。</p>
<p>我实际上只使用 iOS 模拟器。</p>
<p>你知道原因吗? </p>
<p>我正在使用 xaml。</p>
<p>非常感谢。如果您需要更多信息,请告诉我..! </p>
<p>还有我的 App.xaml.cs</p>
<pre><code>public App()
{
InitializeComponent();
MainPage = new HomePage();
}
</code></pre>
<p>这是我的主页:</p>
<pre><code>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);
}
}
</code></pre>
<p>我的主页调用 GameListPage :</p>
<pre><code><ContentPage.Content>
<ListView x:Name="GameListView">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding name}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
</code></pre>
<p>有事件:</p>
<pre><code>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
};
</code></pre>
<p>GamePage 在这里:</p>
<p>gamePage.xaml</p>
<pre><code> <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>
</code></pre>
<p></p>
<p>我把这个内容实际上是为了测试滚动。而且,在另一个 contentPage 中,具有相同的内容,我可以滚动。它就在这个页面上,通过 async Navigation.PushAsync 调用...</p>
<p>已编辑:解决了 StackLayout 与 HeightRequest 到 1500。我的滚动工作现在..临时解决了所以.. 它不正确</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我建议您为您的 View 设置一个 <code>BackgroundColor</code>,例如:</p>
<p><code>ScrollView mainContainer = new ScrollView{
背景颜色 = 颜色.红色
};</code></p>
<p>因此,您可以仔细检查您的 View 实际上是否正在渲染到 <code>ContentPage</code> 本身。</p>
<p>另外一个问题可能是 ScrollView 上没有足够的元素(<code>Label、Image、Entry、Button</code>...随便:<a href="https://developer.xamarin.com/guides/xamarin-forms/user-interface/controls/views/" rel="noreferrer noopener nofollow">https://developer.xamarin.com/guides/xamarin-forms/user-interface/controls/views/</a>)来实际滚动。</p >
<p>为您的 View 设置测试背景颜色,并让我们知道实际问题所在。</p>
<p>还请记住,ScrollView 具有 <code>Content</code> 属性,因此您可以向其添加布局。示例:</p>
<pre><code>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 }
};
</code></pre></p>
<p style="font-size: 20px;">关于ios -ScrollView 进入内容页面推送异步不起作用,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/42674867/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/42674867/
</a>
</p>
页:
[1]