There is a stack layout on my XAML page within the scroll view. In the stack layout, I have one listview and some other stack layouts. I'm getting extra space between listview and Stack layouts.
XAML Page:
<ScrollView>
<StackLayout Spacing="-6">
<ListView Margin="0"
ItemsSource="{Binding List}"
HasUnevenRows="true">
<ListView.ItemTemplate>
<DataTemplate>
<cells:SummaryCell />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<StackLayout>
<StackLayout Spacing="20" Padding="{DynamicResource ItemsLeftRightPadding}">
<Label
FontAttributes="Bold"
Text="{resources:TranslateExtension Text = closure}"/>
<StackLayout
Spacing="3">
<controls:LabelControl
BaseText="{resources:TranslateExtension Text = PONumber}" />
<controls:EntryControl EntryText="{Binding Number}"/>
</StackLayout>
<StackLayout Spacing="3">
<Label Text="{resources:TranslateExtension Text = FirstName}"/>
<controls:GrayBorderedEntryControl EntryText="{Binding FirstName}" I/>
</StackLayout>
<StackLayout Spacing="3">
<Label Text="{resources:TranslateExtension Text = LastName}"/>
<controls:GrayBorderedEntryControl EntryText="{Binding LastName}" IsVisible="True"/>
</StackLayout>
</StackLayout>
<StackLayout
Padding="{DynamicResource SummaryItemsLeftRightPadding}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<controls:AddSignatureControl
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Path="{Binding Signature}" />
</StackLayout>
</StackLayout>
</StackLayout>
</StackLayout>
</ScrollView>
We don't recommend using Listview
inside scrollview
, as this will lead to problems such as those you encounter.
You can try to use Bindable Layouts in Xamarin.Forms to achieve this. This way there will be no such problem.
Please refer to the following code:
<ScrollView >
<StackLayout Spacing="-6">
<StackLayout BindableLayout.ItemsSource="{Binding Items}"
Orientation="Vertical" >
<BindableLayout.ItemTemplate>
<DataTemplate>
<Label Text="{Binding .}" FontSize="30" />
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
<StackLayout >
<!-- other code -->
</StackLayout>
</StackLayout>
</ScrollView>