Xamarin Forms ListView onpressing event

情到浓时终转凉″ 提交于 2021-02-08 02:05:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!