Xamarin, не работает TapGestureRecognizer
Не могу понять почему не работает TapGestureRecognizer Command="{Binding PointViewCommand}" CommandParameter="{Binding Start.RoutePoint}" как будто что то перекрывает. Цепляю туда кнопку, кнопка кликает. Если выношу TapGestureRecognizer в первый StackLayout после ScrollView то работает, но мне это не подходит так как там список и мне нужен клик на конкретную запись.
<ScrollView IsVisible="{Binding IsSetActiveRoute}" IsEnabled="{Binding IsSetActiveRoute}" InputTransparent="True">
<StackLayout BindableLayout.ItemsSource="{Binding RouteListDoc.RowsRoute}" Padding="5">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Frame CornerRadius="5" OutlineColor="#c3c3c3" BackgroundColor="#F2FFFFE0">
<StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand">
<StackLayout Orientation="Horizontal">
<StackLayout HorizontalOptions="StartAndExpand" WidthRequest="125">
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Command="{Binding PointViewCommand}" CommandParameter="{Binding Start.RoutePoint}" />
</StackLayout.GestureRecognizers>
<Label Text="{Binding Start.RoutePoint}" FontAttributes="Bold" FontSize="Large"/>
<Label Text="Вікно доставки:" FontSize="Medium" FontAttributes="Bold" />
<Label Text="{Binding Start.Windows}" FontSize="Medium" />
</StackLayout>
<StackLayout HorizontalOptions="StartAndExpand" WidthRequest="80">
<Image Source="arrow.png" HorizontalOptions="CenterAndExpand" />
<StackLayout Orientation="Horizontal" HorizontalOptions="Center">
<Label Text="Пал:" FontSize="Medium" FontAttributes="Bold" />
<Label Text="{Binding Finish.Pal}" FontSize="Medium" />
</StackLayout>
<StackLayout Orientation="Horizontal" HorizontalOptions="Center">
<Label Text="КГ:" FontSize="Medium" FontAttributes="Bold" />
<Label Text="{Binding Finish.KG}" FontSize="Medium" />
</StackLayout>
<StackLayout Orientation="Horizontal" HorizontalOptions="Center">
<Label Text="КМ:" FontSize="Medium" FontAttributes="Bold" />
<Label Text="{Binding Start.KM}" FontSize="Medium" />
</StackLayout>
</StackLayout>
<StackLayout HorizontalOptions="EndAndExpand" WidthRequest="125">
<Label Text="{Binding Finish.RoutePoint}" FontAttributes="Bold" FontSize="Large" />
<Label Text="Вікно доставки:" FontSize="Medium" FontAttributes="Bold" />
<Label Text="{Binding Finish.Windows}" FontSize="Medium" />
</StackLayout>
</StackLayout>
</StackLayout>
</Frame>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</ScrollView>
Ответы (1 шт):
Пошел путем относительной привязки. Как оказалось нельзя биндить в списке от общей привязки, нужно либо делать обработчик непосредственно в экземпляре коллекции либо так как сделал я, как правильно не знаю.
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/data-binding/relative-bindings
Это шапка:
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:forms="clr-namespace:dotMorten.Xamarin.Forms;assembly=dotMorten.Xamarin.Forms.AutoSuggestBox" xmlns:local="clr-namespace:DriverHelper2.Behavior"
xmlns:view="clr-namespace:DriverHelper2.ViewModel"
x:Class="DriverHelper_v_2._0.View.MainShell"
Shell.BackgroundColor="White"
Shell.TabBarBackgroundColor="White"
Shell.ForegroundColor="Black"
Shell.TabBarTitleColor="Black"
Shell.TitleColor="Black"
Shell.UnselectedColor="Gray"
Shell.TabBarUnselectedColor="Gray"
Shell.TabBarIsVisible="True"
Shell.TabBarForegroundColor="Black"
BindingContext="{Binding Source={RelativeSource Self}, Path=MainViewModel}"
>
Это выборка:
<ScrollView IsVisible="{Binding IsSetActiveRoute}" IsEnabled="{Binding IsSetActiveRoute}" InputTransparent="True">
<StackLayout BindableLayout.ItemsSource="{Binding RouteListDoc.RowsRoute}" Padding="5">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Frame CornerRadius="5" OutlineColor="#c3c3c3" BackgroundColor="#F2FFFFE0">
<StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand">
<StackLayout Orientation="Horizontal">
<StackLayout HorizontalOptions="StartAndExpand" WidthRequest="125">
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Source={RelativeSource AncestorType={x:Type view:MainShellViewModel}}, Path=PointViewCommand}" CommandParameter="{Binding Start.RoutePoint}" />
</StackLayout.GestureRecognizers>
<Label Text="{Binding Start.RoutePoint}" FontAttributes="Bold" FontSize="Large"/>
<Label Text="Вікно доставки:" FontSize="Medium" FontAttributes="Bold" />
<Label Text="{Binding Start.Windows}" FontSize="Medium" />
</StackLayout>
<StackLayout HorizontalOptions="StartAndExpand" WidthRequest="80">
<Image Source="arrow.png" HorizontalOptions="CenterAndExpand" />
<StackLayout Orientation="Horizontal" HorizontalOptions="Center">
<Label Text="Пал:" FontSize="Medium" FontAttributes="Bold" />
<Label Text="{Binding Finish.Pal}" FontSize="Medium" />
</StackLayout>
<StackLayout Orientation="Horizontal" HorizontalOptions="Center">
<Label Text="КГ:" FontSize="Medium" FontAttributes="Bold" />
<Label Text="{Binding Finish.KG}" FontSize="Medium" />
</StackLayout>
<StackLayout Orientation="Horizontal" HorizontalOptions="Center">
<Label Text="КМ:" FontSize="Medium" FontAttributes="Bold" />
<Label Text="{Binding Start.KM}" FontSize="Medium" />
</StackLayout>
</StackLayout>
<StackLayout HorizontalOptions="EndAndExpand" WidthRequest="125">
<Label Text="{Binding Finish.RoutePoint}" FontAttributes="Bold" FontSize="Large" />
<Label Text="Вікно доставки:" FontSize="Medium" FontAttributes="Bold" />
<Label Text="{Binding Finish.Windows}" FontSize="Medium" />
</StackLayout>
</StackLayout>
</StackLayout>
</Frame>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</ScrollView>