My xaml is:
<ContentPage.Resources>
<ResourceDictionary>
<DataTemplate x:Key="displayItemTemplate">
<StackLayout>
<Frame CornerRadius="3" HasShadow="False" Margin="10,2" Padding="5,0"
BorderColor="{Binding BindingContext.AppSettings[MPLVItemFrameBorderColor], Source={x:Reference this}}"
BackgroundColor="{Binding BindingContext.AppSettings[MPLVItemFrameBackgroundColor], Source={x:Reference this}}">
<StackLayout Orientation="Horizontal">
<BoxView BackgroundColor="Transparent" Color="{Binding Status, Converter={StaticResource NoteStatusToColorConverter}}" Margin="4" HeightRequest="32" WidthRequest="32" CornerRadius="5">
<BoxView.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Source={x:Reference this}, Path=BindingContext.NoteStatusSwitchCommand}" CommandParameter="{Binding .}"/>
</BoxView.GestureRecognizers>
</BoxView>
<Label BackgroundColor="Transparent" Text="{Binding Description}" TextDecorations="{Binding Status, Converter={StaticResource NoteStatusConverter}}" HorizontalOptions="FillAndExpand" VerticalTextAlignment="Center" HorizontalTextAlignment="Start">
<Label.GestureRecognizers>
<TapGestureRecognizer NumberOfTapsRequired="2" Command="{Binding Source={x:Reference this}, Path=BindingContext.NoteEditCommand}" CommandParameter="{Binding .}"/>
</Label.GestureRecognizers>
</Label>
<ImageButton BackgroundColor="Transparent" Source="{Binding ItemImagePath, Converter={StaticResource ImagePathToImageSourceConverter}}" HeightRequest="32" WidthRequest="32"><!--Command="{Binding Source={x:Reference this}, Path=BindingContext.ItemImage1TapCommand}" CommandParameter="{Binding .}">-->
<ImageButton.GestureRecognizers>
<TapGestureRecognizer NumberOfTapsRequired="1" Command="{Binding Source={x:Reference this}, Path=BindingContext.ItemImage1TapCommand}" CommandParameter="{Binding .}"/>
<!--<TapGestureRecognizer NumberOfTapsRequired="2" Command="{Binding Source={x:Reference this}, Path=BindingContext.ItemImage2TapsCommand}" CommandParameter="{Binding .}"/>-->
</ImageButton.GestureRecognizers>
</ImageButton>
<ImageButton BackgroundColor="Transparent" Source="NoteDelete.png" HeightRequest="32" WidthRequest="32"
Command="{Binding Source={x:Reference this}, Path=BindingContext.NoteDeleteCommand}" CommandParameter="{Binding .}"/>
</StackLayout>
</Frame>
</StackLayout>
</DataTemplate>
<DataTemplate x:Key="emptyItemTemplate">
<Grid/>
</DataTemplate>
ImageButton中的TapGestureRecognizer命令永远不会被调用。
如果我删除识别器并在ImageButton中添加一个普通的Command属性,则该命令将被调用。
我在这个2天,尝试多个测试和互联网浏览。有谁能帮帮我吗?
注意:按键在中工作良好:
.BoxView
.Label控制
当我ImageButton置评。gestererecogizers,并把Command直接作为ImageButton的属性。
! !找到解决方案了!!
我在StackLayout中包含了ImageButton,在这个StackLayout中包含了Recognizers,在ImageButton中没有更多。
看来问题解决了。
您需要做的就是将ImageButton
移动到StackLayout
中。你必须确保Recognizers
在你创建的StackLayout
里面而不是在ImageButton
里面