问题
I want to change the Image by changing the IconToShow propery with binding (programmatically), when the item is pressing.
How can I trigger an OnPressed event ??
<ListView x:Name="listView" ItemSelected="OnItemSelected" ItemsSource="{Binding MainMenuList}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" IsVisible="{Binding MenuStyle, Converter={StaticResource not}" SeparatorColor="Blue">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10" />
<ColumnDefinition Width="30" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Image Source="{Binding IconToShow}" Grid.Row="0" Grid.Column="1"/>
<Label Text="{Binding Title}" Grid.Row="0" Grid.Column="3"/>
</Grid>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
回答1:
So for LongPress events inside a cell you will need a custom renderer of a cell to do what you need, here are some links that may help you:
https://forums.xamarin.com/discussion/58487/listview-long-press-tap-delete-popup
https://forums.xamarin.com/discussion/18798/detect-long-tap-on-listview-item
https://forums.xamarin.com/discussion/27323/how-can-i-recognize-long-press-gesture-in-xamarin-forms
Hope this helps.
来源:https://stackoverflow.com/questions/38304300/xamarin-forms-listview-onpressing-event