我有一个关于Xamarin StackLayout和ListView的问题。
我在StackLayout中使用Listview。Listview包含10个项目,它们很容易超出堆栈布局高度。我使用了Orientation作为Vertical,使用VerticalOptions作为StackLayout的FillAndExpand。当没有导航标题栏时,StackLayout会得到正确的扩展。问题是,当有导航标题栏时,Stacklayout不能正确扩展,Listview项目会缩小。还有其他人面临这个问题吗?
<ContentPage.Content>
<StackLayout>
<StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" >
<ListView
HasUnevenRows="True"
ItemsSource="{Binding sampleList}"
CachingStrategy="RecycleElement">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<views:sampleView/>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</StackLayout>
</ContentPage.Content> 我已经尝试了下面提到的选项。
1) Setting the Height Request to parent Stack Layout. It worked for some devices and not worked for some devices. 2) Use Grid instead of StackLayout by setting the Grid row definitions like given below. `<Grid.RowDefinitions> <RowDefinition Height="*"></RowDefinition> </Grid.RowDefinitions>` But this change also didn't fix the issue. 3) Use Scroll View instead of StackLayout This will work. But Xamarin suggests we should not nest ScrollView with other controls that provide scrolling, like ListView and WebView. ( [https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/scroll-view](https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/scroll-view) )发布于 2020-08-11 09:34:53
我遇到了同样的问题,老实说我不知道原因,但在我的例子中,我不得不删除stackLayout,并将列表视图保留在ContentPage中。
我想更具体地说明原因,但我只是想知道如果有更多关于它的信息,我会让你知道的。
<ContentPage.Content>
<ListView
HasUnevenRows="True"
ItemsSource="{Binding sampleList}"
CachingStrategy="RecycleElement">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<views:sampleView/>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content> https://stackoverflow.com/questions/59547093
复制相似问题