我有一个包含项目的 CollectionView。我想长按某个项目以让导航调用LongPressCommand
。项目的 DataTemplate 是 3 个标签。
<CollectionView ItemsSource="{Binding FormattedEvents}"
VerticalScrollBarVisibility="Always"
EmptyView="No events recorded."
HeightRequest="500"
SelectedItem="{Binding SelectedMatchEvent}"
SelectionMode="Single">
<CollectionView.Behaviors>
<!--THIS WILL WORK IF I LONG PRESS ON THE EMPTY LIST-->
<toolkit:TouchBehavior LongPressCommand="{Binding LongPressCommand}"/>
</CollectionView.Behaviors>
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid Padding="10" HorizontalOptions="Center">
<Grid.Behaviors>
<!--DOESN'T WORK-->
<toolkit:TouchBehavior LongPressCommand="{Binding LongPressCommand}"/>
</Grid.Behaviors>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Padding="5,0,5,0"
Grid.Column="0"
TextColor="White"
Text="{Binding HomeEventMessage}"
FontSize="Medium">
<Label.Behaviors>
<!--DOESN'T WORK-->
<toolkit:TouchBehavior LongPressCommand="{Binding LongPressCommand}"/>
</Label.Behaviors>
</Label>
<Label Padding="5,0,5,0"
Grid.Column="1"
TextColor="White"
Text="{Binding EventTime}"
HorizontalOptions="Center"
FontSize="Default"/>
<Label Grid.Column="3"
Text="{Binding AwayEventMessage}"
TextColor="White"
FontSize="Medium" >
<Label.Behaviors>
<!--DOESN'T WORK-->
<toolkit:TouchBehavior LongPressCommand="{Binding LongPressCommand}"/>
</Label.Behaviors>
</Label>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>