Is it possible to have ONE touch for a certain function (now I have to select an item using ItemTapped
) and TWO touches on the same ListView
to do another function?
I did not get this information from Microsoft's website and from 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 am trying to test what was passed to me by @AmadeuAntunes and I have not gotten it (I am very new to programming), it gives error on this line btnClick.Clicked + = (sender, e) = & gt ;.
The error:
OXAML:
<StackLayout><ButtonText="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;
}
}
}
}