Xaml 在android中点击事件不触发命令
我有如下xamarin表单中的listview模板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
<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>