Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 15671

Maui LOngPress Command [closed]

$
0
0

I'm trying to use the new behavior of Maui Community Toolkit, LongPress. When I press a line in the colectionview the data returned isn't the correct one. I show here my page

<?xml version="1.0" encoding="utf-8" ?><ContentPage       xmlns="http://schemas.microsoft.com/dotnet/2021/maui"      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"                 x:Class="ZebraMauiFG.Pages.Telemoveis"                 xmlns:behaviors="clr-namespace:ZebraMauiFG"                 xmlns:viewmodel="clr-            namespace:ZebraMauiFG.ViewModels"                 x:DataType="viewmodel:TelemoveisPageViewModel"                 xmlns:models="clr-namespace:ZebraMauiFG.Models"     xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"                 Title="Telemoveis"><CollectionView x:Name="Codigos"  HeightRequest="260"                  ItemsUpdatingScrollMode="KeepLastItemInView"                        ItemSizingStrategy="MeasureFirstItem"                        ItemsSource="{Binding Codigos}"                        SelectionMode="Single"     >                                           <CollectionView.ItemTemplate><DataTemplate x:DataType="models:EncomendaDetalhes"><StackLayout Orientation="Vertical"       VerticalOptions="FillAndExpand" Padding="3" Grid.Column="0"><Grid Margin="0" ColumnSpacing="0"     Padding="5,0,0,0"  RowSpacing="2"  VerticalOptions="Center" ><Grid.RowDefinitions >                                       <RowDefinition Height="22" /></Grid.RowDefinitions><Grid.ColumnDefinitions ><ColumnDefinition Width="160" /><ColumnDefinition Width="140" /><ColumnDefinition Width="60" /></Grid.ColumnDefinitions><Label Grid.Row="0" Grid.Column="0" FontSize="16"  Text="    {Binding IMEI}"   VerticalTextAlignment ="Center" ><Label.Behaviors><toolkit:TouchBehavior                                                  LongPressCommandParameter="{Binding .}"              LongPressCommand="{Binding Source={x:Reference      Codigos},  Path=BindingContext.LongPressCommand}"              LongPressDuration="1000" />                                      </Label.Behaviors>        </Label>  </Grid>               </StackLayout></DataTemplate></CollectionView.ItemTemplate></CollectionView></ContentPage.Content></ContentPage>   

If I do a LongPress on a line on the grid, I get the wrong data.

This is the viewmodel function called

public async void LongPress(EncomendaDetalhes encDet){    var resposta = await          Application.Current.MainPage.DisplayAlert("Apagar IMEI ",            encDet.IMEI, "Sim", "Não");    if (resposta)    {        await _encomendaservice.DeleteEncomendaDetalhes(encDet);        Codigos.Remove(encDet);        int iTmp = int.Parse(Lidos) - 1;        Lidos = iTmp.ToString();    }}

For instance

enter image description here
enter image description here

As you can see the data returned is not the one I pressed.

The viewmodel function just removes the item from CollectionView and database. I don't know how to reference the right viewmodel.


Viewing all articles
Browse latest Browse all 15671

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>