【问题标题】:How to make a Listview overlap a stacklayout in Xamarin Forms?如何使 Listview 与 Xamarin Forms 中的堆栈布局重叠?
【发布时间】:2019-04-01 19:21:33
【问题描述】:

我正在尝试做我自己的自动完成控制,我已经用 stacklayout 完成了这个,我在里面放置了一个网格,在这个里面有一个搜索栏和一个 lisview,问题出现了,这样我总是必须有固定的高度已定义。

如果我将 Stacklayout 更改为 AbsoluteLayout 它会更好一些,但是当我加载时列表位于我下面的 stacklayout 后面,我无法选择最后的项目,我想问题是因为 stacklayout与 listview 重叠,我想知道如何反向操作,即 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 后面,我无法选择任何内容。

【问题讨论】:

  • imgur.com/1k1kmxc -> ListView Inside AbsolutLayout imgur.com/x4dj3ev -> ListView inside StackLayout
  • 如果您希望 ListView 在 StackLayout 之上,那么将 StackLayout before ListView 在 XAML 中
  • @Jason wao,经过这么多小时的尝试,这正是我所需要的,这对我有帮助,非常感谢。

标签: c# listview xamarin xamarin.forms


【解决方案1】:

我希望列表视图会在堆栈布局之上

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

示例如下:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多