【发布时间】:2020-04-20 03:49:42
【问题描述】:
我有一个关于 Xamarin StackLayout 和 ListView 的问题。
我在 StackLayout 中使用 Listview。 Listview 包含 10 个项目,很容易超出 stacklayout 的高度。对于 StackLayout,我将 Orientation 用作 Vertical,将 VerticalOptions 用作 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)将高度请求设置为父堆栈布局。
它适用于某些设备,但不适用于某些设备。
2) 通过设置如下所示的 Grid 行定义来使用 Grid 而不是 StackLayout。
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
但此更改也没有解决问题。
3) 使用 Scroll View 而不是 StackLayout
这将起作用。但 Xamarin 建议我们不应将 ScrollView 与其他提供滚动的控件嵌套,如 ListView 和 WebView。
(https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/scroll-view)
【问题讨论】:
-
对不起,根据我的演示,我无法重现这个问题。您能否发一个minimal-reproducible-example 以便我们尝试在我们这边重现这个问题?
-
顺便说一句,
<StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" />最后应该有一个额外的字符/。 -
感谢@JessieZhang-MSFT 的回复。我将很快添加一个可重现的示例。你说的第二部分是对的。我已经更新了问题。
-
嗨,@Ane,您可以在上传可重现的示例后分享链接吗?
标签: listview xamarin xamarin.forms stacklayout