Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xaml 在android中点击事件不触发命令_Xaml_Xamarin_Xamarin.forms_Xamarin.android - Fatal编程技术网

Xaml 在android中点击事件不触发命令

Xaml 在android中点击事件不触发命令,xaml,xamarin,xamarin.forms,xamarin.android,Xaml,Xamarin,Xamarin.forms,Xamarin.android,我有如下xamarin表单中的listview模板 <ListView x:Name="lstSections" Grid.Row="0" Grid.Column="1" ItemsSource="{Binding DataList}"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <Grid Margin

我有如下xamarin表单中的listview模板

<ListView 
x:Name="lstSections"
Grid.Row="0"
Grid.Column="1"
ItemsSource="{Binding DataList}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <Grid Margin="0,0,0,10">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <input:CheckBox IsEnabled="False" HorizontalOptions="FillAndExpand" IsChecked="{Binding Selected}" Grid.Column="0"></input:CheckBox>
                    <StackLayout VerticalOptions="CenterAndExpand" Grid.Column="1">
                        <Label Text="{Binding Name}" VerticalOptions="Fill" HorizontalOptions="StartAndExpand">
                        </Label>
                        <!--<Label Text="{Binding Data.Description}" VerticalOptions="Fill" FontSize="10" HorizontalOptions="StartAndExpand" />-->
                    </StackLayout>
                    <Grid.GestureRecognizers>
                        <ClickGestureRecognizer Command="{Binding ShowSectionCommand}" CommandParameter="{Binding Id}" />
                        <TapGestureRecognizer Command="{Binding ShowSectionCommand}" CommandParameter="{Binding Id}" />
                    </Grid.GestureRecognizers>
                </Grid>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
    <ListView.Footer>
        <Button Text="Save" Command="{Binding FinishCommand}" />
    </ListView.Footer>
</ListView>

我宣布命令如下:

public ICommand ShowSectionCommand
    {
        get
        {
            return new AsyncCommand(async (val) => {
                await NavigationService.NavigateToAsync<InspectionFormViewModel>(val);
            });
        }
    }
public ICommand showsection命令
{
收到
{
返回新的async命令(async(val)=>{
等待NavigationService.NavigateToAsync(val);
});
}
}
该命令在uwp应用程序上运行良好,但在Android中不起作用,
请建议一些解决此问题的指针。

这是因为您没有将其绑定到正确的上下文中。
数据模板中的
手势识别器应类似于:

 <Grid.GestureRecognizers>  
 <TapGestureRecognizer Command="{Binding BindingContext.ShowSectionCommand, Source={x:Reference lstSections}}" CommandParameter="{Binding Id}" />
 </Grid.GestureRecognizers>