如何在Xamarin Forms中使Listview与StackLayout重叠?

时间:2019-04-01 19:21:33

标签: c# listview xamarin xamarin.forms

我正在尝试做自己的自动完成控制,我已经用stacklayout做到了这一点,并且在内部放置了一个网格,并在其中放置了一个搜索栏和一个lisview,问题是,以这种方式,我总是必须要固定高度已定义。

如果我将AbsoluteLayout的Stacklayout更改为更好,但是加载时的列表位于我下面的stacklayout后面,并且我无法选择最后一个项目,我想问题是因为s​​tacklayout我想知道如何反向执行该操作,即Listview与stacklayout重叠。

                 <AbsoluteLayout    
                           Grid.Column="1"
                           Grid.Row="0"
                           IsVisible="{Binding IsVisibleSearchBarClienteBinding}"
                        >
                        <SearchBar
                                Placeholder="Buscar Cliente"
                                HeightRequest="32"
                                Text="{Binding SearchCustomer}"
                            >
                            <SearchBar.Behaviors>
                                <behaviors:EventHandlerBehavior EventName="TextChanged">
                                    <behaviors:InvokeCommandAction Command="{Binding RefreshSearchCustomerCommand}" />
                                </behaviors:EventHandlerBehavior>
                            </SearchBar.Behaviors>
                        </SearchBar>
                        <!--Buscar Clientes-->
                        <ListView
                                BackgroundColor="Transparent"       
                                ItemsSource="{Binding CustomerObseravableBinding}"
                                IsVisible="{Binding IsVisibleListViewSearchBarBinding}"
                                IsPullToRefreshEnabled="true"
                                Margin="0,5,0,0"
                                RefreshCommand="{Binding RefreshListCustomerCommand}"
                                SeparatorVisibility="Default"    
                                VerticalOptions="StartAndExpand"
                            >
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <ViewCell>
                                        <Grid
                                                HeightRequest="40">
                                            <Label 
                                                    Grid.Row="0"
                                                    Text="{Binding Name}" FontSize="16">
                                            </Label>
                                            <Label 
                                                    Grid.Row="1"
                                                    Text="{Binding VATRegistrationNo}"  FontSize="12">
                                            </Label>
                                            <Grid.GestureRecognizers>
                                                <TapGestureRecognizer Command="{Binding SelectedCustomerFromSearchBarCommand}"/>
                                            </Grid.GestureRecognizers>
                                        </Grid>

                                    </ViewCell>

                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
                        <!--</StackLayout>-->

                    </AbsoluteLayout>

我希望列表视图位于堆栈布局上方,而堆栈布局位于下方,我可以从中选择项目。但是目前,该列表仍然位于stacklayout后面,我什么也无法选择。

1 个答案:

答案 0 :(得分:1)

  

我希望列表视图位于堆栈布局上方

如Jason所说,您需要将 StackLayout 放在XAML中的 ListView 之前。

示例如下:

<StackLayout>...</StackLayout>
<ListView>...</ListView>