Xamarin Forms Listview中的TapGestureRecognition

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

我需要检查Xamarin Forms Listview的空白部分是否被点击。例如,有5行,在那些填充行下方的空间被点击,应调用一个方法。我尝试将Tapgesturerecognizer添加到Listview和包含listview的页面,但这没有用。有没有办法检查是否有人在列表视图中点击了空白?

<ListView x:Name="ItemsListView"
                ItemsSource="{Binding Items}"
                VerticalOptions="FillAndExpand"
                HasUnevenRows="true"
                RefreshCommand="{Binding LoadItemsCommand}"
                IsPullToRefreshEnabled="true"
                IsRefreshing="{Binding IsBusy, Mode=OneWay}"
                CachingStrategy="RecycleElement"
                ItemSelected="OnItemSelected">
            <d:ListView.ItemsSource>
                <x:Array Type="{x:Type x:String}">
                    <x:String>First Item</x:String>
                    <x:String>Second Item</x:String>
                    <x:String>Third Item</x:String>
                    <x:String>Fourth Item</x:String>
                    <x:String>Fifth Item</x:String>
                    <x:String>Sixth Item</x:String>
                </x:Array>
            </d:ListView.ItemsSource>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Padding="10">
                            <Label Text="{Binding Text}" 
                                d:Text="{Binding .}"
                                LineBreakMode="NoWrap" 
                                Style="{DynamicResource ListItemTextStyle}" 
                                FontSize="16" />
                            <Label Text="{Binding Description}" 
                                d:Text="Item descripton"
                                LineBreakMode="NoWrap"
                                Style="{DynamicResource ListItemDetailTextStyle}"
                                FontSize="13" />
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>

            </ListView.ItemTemplate>
            <ListView.GestureRecognizers>
                <TapGestureRecognizer Tapped="OnTapGestureRecognizerTapped" NumberOfTapsRequired="1"></TapGestureRecognizer> 
            </ListView.GestureRecognizers>
        </ListView>
forms listview xamarin
1个回答
0
投票

[签出此https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/listview/interactivity#selection-and-taps。它讨论了ListView中的选择活动,因此您可以执行一些逻辑(当选择一个项目时)

更新:Remove Code in the Screenshot然后配置LinkView中的ListView项目选择。

然后将ListView(确保列表视图仅填充其所需的空间)在StackLayout中,并使用单击空白页时需要执行的逻辑来配置stackLayout的Tapped事件。

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