I have a list view which contains cells like this :
<StackLayout Orientation="Horizontal" Margin="30,0,20,0" VerticalOptions="Center">
<Label Grid.Row="0" Text="{Binding AppointmentPatientName}" VerticalOptions="Center" HorizontalOptions="StartAndExpand" Style="{StaticResource labelView}"/>
<Label Grid.Row="0" Grid.Column="2" Text="{Binding AppointmentDate.Date}" Font="Small" HorizontalOptions="CenterAndExpand" Style="{StaticResource labelView}" />
<Label x:Name="Delete Button" Text="X"></Label>
</StackLayout>
How can I activate this label in order to make it Delete from firebase database it's smth like this :
private async void ItemImageButton_Clicked(object sender, EventArgs e)
{
var appoitment = (Appoitment)((ImageButton)sender).CommandParameter;
AppintmentService appintmentService = new AppintmentService();
await appintmentService.DeleteFollowup(appoitment.PatientID, appoitment.ID);
await DisplayAlert("Delted", "The patient Deleteed", "Ok");
await Navigation.PushAsync(new PatientProfileFollowUpPage());
}
but i want it for label not ImgButton and want activate it in viewmodel page
CodePudding user response:
i want it for label not ImgButton and want activate it in viewmodel page
Yes, you can use TapGestureRecognizer
and MVVM to achieve this.
Based on your code ,I made a simple demo.You can refer to the following code:
<ContentPage.BindingContext>
<tapapp1:MyViewModel></tapapp1:MyViewModel>
</ContentPage.BindingContext>
<StackLayout Orientation="Horizontal" Margin="30,0,20,0" VerticalOptions="Center">
<Label Text="{Binding AppointmentPatientName}" VerticalOptions="Center" HorizontalOptions="StartAndExpand" />
<Label Grid.Column="2" Text="{Binding AppointmentDate}" Font="Small" HorizontalOptions="CenterAndExpand" />
<Label x:Name="Delete" Text="X" >
<Label.GestureRecognizers>
<TapGestureRecognizer Command="{Binding TapCommand}"
/>
</Label.GestureRecognizers>
</Label>
</StackLayout>
MyViewModel.cs
public class MyViewModel
{
public string AppointmentPatientName { get; set; }
public string AppointmentDate { get; set; }
public ICommand TapCommand => new Command(RemoveItem);
private void RemoveItem()
{
// add your code here
}
public MyViewModel()
{
AppointmentPatientName = "Test1";
AppointmentDate = "2022-4-28";
}
}
Note: You can modify above code based on your requirement.