我使用MR.Gestures插件来处理单个点击和长时间按下的事件。
<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>函数下面的服务调用后的将我的数据分成两列,并返回可观察的集合.
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”是我长期被压制的事件
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)
发布于 2018-08-22 08:46:11
你看过这个吗?免费的GestureSample应用程序从GitHub
长按事件一旦在开始事件和结束事件中调用,就可以区分状态为.When,状态等于结束直接返回,并在状态等于开始时执行一些操作(例如,填充UI )。
https://stackoverflow.com/questions/51961537
复制相似问题