Xamarin Forms ListView发生事件 [英] Xamarin Forms ListView onpressing event

查看:50
本文介绍了Xamarin Forms ListView发生事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当项目被按下时,我想通过绑定(以编程方式)更改具有绑定的IconToShow属性来更改Image.

如何触发OnPressed事件?

 < ListView x:Name ="listView" ItemSelected ="OnItemSelected" ItemsSource ="{Binding MainMenuList}" Horizo​​ntalOptions ="FillAndExpand" VerticalOptions ="FillAndExpand" IsVisible ="{Binding MenuStyle,Converter = {StaticResourcenot}"SeparatorColor =" Blue>< ListView.ItemTemplate>< DataTemplate>< ViewCell>< ViewCell.View><网格>< Grid.RowDefinitions>< RowDefinition Height ="50"/></Grid.RowDefinitions><Grid.ColumnDefinitions>< ColumnDefinition Width ="10"/>< ColumnDefinition Width ="30"/>< ColumnDefinition Width ="10"/>< ColumnDefinition Width ="Auto"/></Grid.ColumnDefinitions><图片来源="{Binding IconToShow}" Grid.Row ="0" Grid.Column ="1"/><标签文本="{绑定标题}" Grid.Row ="0" Grid.Column ="3"/></Grid></ViewCell.View></ViewCell></DataTemplate></ListView.ItemTemplate></ListView> 

解决方案

因此,对于单元格内的LongPress事件,您将需要一个单元格的自定义渲染器来执行所需的操作,以下一些链接可能会对您有所帮助:

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形式

希望这会有所帮助.

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>

解决方案

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.

这篇关于Xamarin Forms ListView发生事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆