首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >长时间按下MR.grid事件(在列表视图中)在IOS中xamarin.forms中调用两次

长时间按下MR.grid事件(在列表视图中)在IOS中xamarin.forms中调用两次
EN

Stack Overflow用户
提问于 2018-08-22 07:12:32
回答 1查看 194关注 0票数 0

我使用MR.Gestures插件来处理单个点击和长时间按下的事件。

代码语言:javascript
复制
<ListView Grid.Row="1"  x:Name="lstProducts" HasUnevenRows="True" SeparatorVisibility="None" BackgroundColor="Transparent" IsPullToRefreshEnabled="True" Refreshing="lstProducts_Refreshing">
                    <ListView.ItemTemplate>
                        <DataTemplate >
                            <ViewCell>
                                <ViewCell.View>
                                    <Grid>
                                        <Grid.Margin>
                                            <OnIdiom x:TypeArguments="Thickness" Phone="10" Tablet="20"/>
                                        </Grid.Margin>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="*"/>
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="{Binding grdRowHeight}"/>
                                        </Grid.RowDefinitions>
                                        <mr:Grid x:Name="grd_left_product" Grid.Column="0" Grid.Row="0" ClassId="{Binding Left_attachedFilePath}" Style="{StaticResource MostOuterGridForBorder}"
                                                 Tapped="grd_left_product_Tapped" 
                                                 LongPressed="grd_left_product_DoubleTapped">
                                            <Grid Style="{StaticResource OuterGrid}">
                                                <ffimageloading:CachedImage Source="{Binding Left_thumbnailImage}" Style="{StaticResource ThumbNailImageStyle}" />
                                                <StackLayout VerticalOptions="EndAndExpand" >
                                                    <custom:CustomWrapLabel Text="{Binding Left_name}" Style="{StaticResource CustomWrapLabelStyle}"/>
                                                </StackLayout>
                                                <StackLayout IsVisible="{Binding Left_IsChecked}" Style="{StaticResource MultipleDownloadStack}">
                                                    <ffimageloading:CachedImage Source="check_ic.png" Style="{StaticResource MultipleDownloadCheckIcon}" />
                                                </StackLayout>
                                            </Grid>
                                        </mr:Grid>
                                        <mr:Grid x:Name="grd_right_product" Grid.Column="1" Grid.Row="0" ClassId="{Binding Right_attachedFilePath}" Style="{StaticResource MostOuterGridForBorder}" IsVisible="{Binding Right_grd_product_visibility}"
                                                 Tapped="grd_right_product_Tapped" 
                                                 LongPressed="grd_right_product_DoubleTapped">
                                            <Grid Style="{StaticResource OuterGrid}">
                                                <ffimageloading:CachedImage Source="{Binding Right_thumbnailImage}" Style="{StaticResource ThumbNailImageStyle}" />
                                                <StackLayout VerticalOptions="EndAndExpand" >
                                                    <custom:CustomWrapLabel Text="{Binding Right_name}" Style="{StaticResource CustomWrapLabelStyle}" />
                                                </StackLayout>
                                                <StackLayout IsVisible="{Binding Right_IsChecked}" Style="{StaticResource MultipleDownloadStack}">
                                                    <ffimageloading:CachedImage Source="check_ic.png" Style="{StaticResource MultipleDownloadCheckIcon}" />
                                                </StackLayout>
                                            </Grid>
                                        </mr:Grid>
                                    </Grid>
                                </ViewCell.View>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>

函数下面的服务调用后的将我的数据分成两列,并返回可观察的集合.

代码语言:javascript
复制
private ObservableCollection<ProductData> BifurcationInLeftRight(List<ResponseDetail> lstResponseDetail)
        {
            lstcollectionproductDatas = new ObservableCollection<ProductData>();
            for (int i = 0; i < lstResponseDetail.Count; i++)
            {
                var items = new ProductData();
                items.Left_IsChecked = false;
                items.Right_IsChecked = false;
                items.Left_productId = lstResponseDetail[i].productId;
                items.Left_name = lstResponseDetail[i].name;
                items.Left_attachedFilePath = lstResponseDetail[i].attachedFilePath;
                items.Left_attachedLink = lstResponseDetail[i].attachedLink;
                items.Left_thumbnailImage = lstResponseDetail[i].thumbnailImage;

                i++;
                if (i < lstResponseDetail.Count)
                {
                    items.Right_productId = lstResponseDetail[i].productId;
                    items.Right_name = lstResponseDetail[i].name;
                    items.Right_attachedFilePath = lstResponseDetail[i].attachedFilePath;
                    items.Right_attachedLink = lstResponseDetail[i].attachedLink;
                    items.Right_thumbnailImage = lstResponseDetail[i].thumbnailImage;
                    items.Right_grd_product_visibility = true;
                }
                else
                {
                    items.Right_productId = null;
                    items.Right_name = null;
                    items.Right_attachedFilePath = null;
                    items.Right_attachedLink = null;
                    items.Right_thumbnailImage = null;
                    items.Right_grd_product_visibility = false;

                    items.grdRowHeight = ThumbNailHeight;
                    lstcollectionproductDatas.Add(items);
                    break;
                }
                items.grdRowHeight = ThumbNailHeight;
                lstcollectionproductDatas.Add(items);
            }
            return lstcollectionproductDatas;
        }

在长按下,我检查了项目并重新绑定了我的整个项目源。"grd_left_product_DoubleTapped“和"grd_right_product_DoubleTapped”是我长期被压制的事件

代码语言:javascript
复制
private void grd_left_product_DoubleTapped(object sender, MR.Gestures.LongPressEventArgs e)
        {
            try
            {
                var productId = sender as Grid;
                if (!string.IsNullOrEmpty(productId.ClassId) && lstcollectionproductDatas != null && lstcollectionproductDatas.Count > 0)
                {
                    var selectedObject = lstcollectionproductDatas.Where(d => d.Left_attachedFilePath == productId.ClassId).FirstOrDefault();
                    if (selectedObject != null)
                    {
                        int index = lstcollectionproductDatas.IndexOf(selectedObject);
                        if (!selectedObject.Left_IsChecked)
                            lstcollectionproductDatas[index].Left_IsChecked = true;
                        else
                            lstcollectionproductDatas[index].Left_IsChecked = false;
                    }
                    lstProducts.ItemsSource = null;
                    lstProducts.ItemsSource = lstcollectionproductDatas;
                }
                else
                    new ShowSnackbar(AppResources.Validation_FileNotFound_Message);
            }
            catch (Exception)
            {
                new ShowSnackbar(AppResources.Validation_Exception);
            }
        }

问题:

这段代码在android中运行良好,但在IOS中,当我长时间按一个项目时,它会被选中,但是当我长时间按下来自不同行的另一个项时,长时间按下事件调用两次。

第一次检查前一项,第二次检查我们要检查的项目。这就是为什么第一次已经被检查过的东西没有被检查过。

我的问题是,为什么长时间按下事件在MR.Gestures中调用两次?

有三行(索引- 0,1,2)

  1. 选中索引-2中的左项。
  2. 现在我长时间按住索引-1的左项。
  3. 新闻发布会打了两次。
  4. 第一次对索引-2和未选中选定的项目。
  5. 第二次进行索引-1检查。
EN

回答 1

Stack Overflow用户

发布于 2018-08-22 08:46:11

你看过这个吗?免费的GestureSample应用程序从GitHub

长按事件一旦在开始事件和结束事件中调用,就可以区分状态为.When,状态等于结束直接返回,并在状态等于开始时执行一些操作(例如,填充UI )。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51961537

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档