Xamarin.Forms为什么PopUp视图中两个堆栈布局之间有这么多空间

问题描述 投票:0回答:1

enter image description here```

<pages:PopupPage.Resources>
        <local1:ChangeFrameBackgroudColor x:Key="ChangeFrameBackgroudColor" />
    </pages:PopupPage.Resources>

    <pages:PopupPage.Animation>
        <animations:ScaleAnimation DurationIn="400"
                                   DurationOut="300"
                                   EasingIn="SinOut"
                                   EasingOut="SinIn"
                                   HasBackgroundAnimation="True"
                                   PositionIn="Center"
                                   PositionOut="Center"
                                   ScaleIn="1.2"
                                   ScaleOut="0.8" />
    </pages:PopupPage.Animation>

    <StackLayout Margin="12"

                 BackgroundColor="WhiteSmoke"
                 HorizontalOptions="Center"
                 VerticalOptions="Center"
                 >
        <StackLayout>

            <ListView x:Name="list" HasUnevenRows="True"  ItemsSource="{Binding Firms}" SelectedItem="{Binding FirmId} " Header="{Binding}" ItemTapped="Choose_firm" SelectionMode="Single" Margin="0"  >
                <ListView.ItemTemplate >
                    <DataTemplate>
                        <local:ExtendedViewCell SelectedBackgroundColor="WhiteSmoke"  >

                            <StackLayout  Padding="20, 10"  >
                                <Frame x:Name="frameLabel" BorderColor="#2188ff" BackgroundColor="{Binding IsActive, Converter={StaticResource ChangeFrameBackgroudColor}}" CornerRadius="10">
                                    <Label  FontAttributes="Bold" FontSize="18" TextColor="Black" Text="{Binding Name}" ></Label>
                                </Frame>
                            </StackLayout>

                        </local:ExtendedViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
                <ListView.HeaderTemplate>
                    <DataTemplate>
                        <ContentView BackgroundColor="#006BE6" >
                            <Label Margin="10" HorizontalOptions="CenterAndExpand" Text="Choose Firm"  TextColor="White" FontSize="20" FontAttributes="Bold"/>
                        </ContentView>
                    </DataTemplate>
                </ListView.HeaderTemplate>
            </ListView>
            <StackLayout VerticalOptions="End" Orientation="Horizontal" >
                <Label Text="Check Default:"  FontSize="18" />
                <CheckBox  IsChecked="False" Color="#006BE6" ></CheckBox>
            </StackLayout>
            </StackLayout>

        <StackLayout Orientation="Horizontal" VerticalOptions="Center" HorizontalOptions="Center" Margin="0,0,0,10">
            <Button Text="CHANGE"  BackgroundColor="#006BE6" IsEnabled="{Binding !IsBusy}" TextColor="White" Command="{Binding LoadFirmCommand}" CommandParameter="{Binding FirmId}" CornerRadius="10"></Button>
            <Button Text="CANCEL"  BackgroundColor="Gray" IsEnabled="{Binding !IsBusy}" TextColor="White" Clicked="ClosePopUp" CornerRadius="10"></Button>
        </StackLayout>
    </StackLayout>

</pages:PopupPage>

在第一个StackLayout中,我得到了只有3个元素的ListView。之后是很多空白,在PopUp的底部是另外两个StackLayouts。我尝试使用Margins,Padding,但没有任何变化。我不知道是什么问题。为什么会有那么多空间。底部的两个StackLayouts之间没有空格。如何解决这个空白?

xamarin.forms xamarin.android xamarin.ios
1个回答
0
投票
我还没有运行您的代码,但是,查看您的XAML,我们可以在垂直选项中看到您的堆栈布局,我们告诉它结束

<StackLayout VerticalOptions="End" Orientation="Horizontal" > <Label Text="Check Default:" FontSize="18" /> <CheckBox IsChecked="False" Color="#006BE6" ></CheckBox>

但是,请注意如何将其包装在父堆栈布局中。由于没有高度要求,因此它仅遵循要求的高度。父堆栈布局是定义列表视图的布局。因此,它加载了列表视图,然后在底部(End)呈现了其他堆栈布局,确实造成了巨大的差距所以本质上:

<StackLayout VerticalOptions="End" Orientation="Horizontal" > <Label Text="Check Default:" FontSize="18" /> <CheckBox IsChecked="False" Color="#006BE6" ></CheckBox> </StackLayout> </StackLayout>

转到:

</StackLayout> <StackLayout VerticalOptions="End" Orientation="Horizontal" > <Label Text="Check Default:" FontSize="18" /> <CheckBox IsChecked="False" Color="#006BE6" ></CheckBox> </StackLayout>

© www.soinside.com 2019 - 2024. All rights reserved.