0
It is possible to have ONE touch for a certain function (today I have to select an item using ItemTapped
) AND TWO TOUCHES OF THE SAME ListView
to do another function?
I did not get this information on the Microsoft website and in any other source.
My XAML:
<!-- ListView -->
<ListView x:Name="lstCompra"
BackgroundColor="Aqua"
SeparatorColor="DodgerBlue"
ItemTapped="Compra_OnItemTapped"
HasUnevenRows="True"
Margin="10, 0, 10, 10">
<!-- HasUnevenRows = Serve para fazer com que o conteúdo digitado não seja cortado -->
<ListView.ItemTemplate>
<!-- DataTemplate = exibe dados de uma coleção de objetos em um ListView -->
<DataTemplate>
<ViewCell>
<Grid Margin="2">
<!-- Linhas -->
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- Colunas -->
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!-- Código -->
<StackLayout Grid.Row="0"
Grid.Column="0"
Orientation="Horizontal">
<Label Text="S.C.:"
FontSize="Small"/>
<Label Text="{Binding ID_SOLCOMPRA}"
FontSize="Small"
TextColor="Black"/>
</StackLayout>
<!-- Data -->
<StackLayout Grid.Row="0"
Grid.Column="1"
Orientation="Horizontal">
<Label Text="Data:"
FontSize="Small"
HorizontalOptions="Start"/>
<Label Text="{Binding DT_CADASTRO}"
FontSize="Small"
TextColor="Black"
HorizontalOptions="Start"/>
</StackLayout>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
My C#:
//Selecionando item da lista
private void Compra_OnItemTapped(object sender, ItemTappedEventArgs e)
{
solicita = (sender as ListView).SelectedItem as SolicitarCompra;
}
I’m trying to test what was passed to me by @Amadeuantunes and I haven’t succeeded (I’m very new to programming), gives error in this line btnClick.Clicked += (Sender, and) =>.
The mistake:
THE XAML:
<StackLayout>
<Button Text="Teste"
Clicked="Btn_Teste"
x:Name="btnClick"/>
</StackLayout>
The code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace Teste
{
public partial class MainPage : ContentPage
{
int ButtonCount = 0;
public MainPage()
{
InitializeComponent();
}
void Btn_Teste(object sender, EventArgs e)
{
btnClick.Clicked += (sender, e) =>
{
if (ButtonCount < 1)
{
TimeSpan tt = new TimeSpan(0, 0, 1);
Device.StartTimer(tt, TestHandleFunc);
}
ButtonCount++;
};
bool TestHandleFunc()
{
if (ButtonCount > 1)
{
//Your action for Double Click here
DisplayAlert("", "Two Clicks", "OK");
}
else
{
//Your action for Single Click here
DisplayAlert("", "One Click", "OK");
}
ButtonCount = 0;
return false;
}
}
}
}
show the code
– Leandro Angelo
Added the code @Leandroangelo
– Deivid Souza
You are learning or working with Xamarim?
– Marconi
Both, I’m learning at work rs. My practice has been in a real app.
– Deivid Souza