C# 表单:在<;中添加要映射的单击事件;网格>;?

C# 表单:在<;中添加要映射的单击事件;网格>;?,c#,xamarin,xamarin.forms,xamarin.android,visual-studio-2017,C#,Xamarin,Xamarin.forms,Xamarin.android,Visual Studio 2017,当我点击按钮时,我终于能够使用显示列表视图。这是xaml: <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:maps="clr-namespace:Xamar

当我点击
按钮时,我终于能够使用
显示
列表视图。这是xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
             xmlns:local="clr-namespace:GasStations"
             x:Class="GasStations.MainPage">

    <Grid RowSpacing="0">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="50" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <StackLayout Grid.Row="0" x:Name="MapGrid">
            <maps:Map WidthRequest="960" HeightRequest="200" 
                  x:Name="MyMap" IsShowingUser="true"/>
        </StackLayout>
        <StackLayout Grid.Row="1">
            <Button Text="Show List" x:Name="Button_DisplayList"
                VerticalOptions="CenterAndExpand"
                HorizontalOptions="Center"
                Clicked="OnButtonClicked" />
        </StackLayout>
        <StackLayout Grid.Row="2" x:Name="listSection" IsVisible="false" HeightRequest="200">
            <ListView x:Name="ListView_Pets">
                <ListView.ItemsSource>
                    <x:Array Type="{x:Type x:String}">
                        <x:String>dog</x:String>
                        <x:String>cat</x:String>
                        <x:String>bird</x:String>
                    </x:Array>
                </ListView.ItemsSource>
            </ListView>
        </StackLayout>
    </Grid>
</ContentPage>
当我单击按钮时,将显示ListView并隐藏按钮。到目前为止还不错

一旦打开了
列表视图
,当我点击地图时,如何再次隐藏列表视图

我试着使用
手势识别器
,但它无法构建

感谢您的帮助

我加入了截图,因为我还在学习术语


在地图的父堆栈布局上添加手势识别器

在xaml上:

 <StackLayout Grid.Row="0" x:Name="MapGrid">
  <StackLayout.GestureRecognizer>
    <TapGestureRecognizer Tapped="OnMapAreaTapped"/>
  </StackLayout.GestureRecognizer>
       <maps:Map WidthRequest="960" HeightRequest="200" x:Name="MyMap" IsShowingUser="true"/>
  </StackLayout>

尝试使用聚焦事件,谢谢。我尝试使用它,但我得到了一个错误:
在类型“StackLayout”中找不到可附加属性“GestureRecognizer”
我没有遇到这样的错误,在
StackLayout
上添加
GestureRecognizer
对我来说效果很好。你的Xamarin.nuget表单更新了吗@fdkgfosfskjdlsjdlkfsf
 <StackLayout Grid.Row="0" x:Name="MapGrid">
  <StackLayout.GestureRecognizer>
    <TapGestureRecognizer Tapped="OnMapAreaTapped"/>
  </StackLayout.GestureRecognizer>
       <maps:Map WidthRequest="960" HeightRequest="200" x:Name="MyMap" IsShowingUser="true"/>
  </StackLayout>
private void OnMapAreaTapped(object sen, EventArgs e)
        {
           listSection.IsVisible = false;
           Button_DisplayList.IsVisible = true;
        }