我有一個串列視圖,其中包含這樣的單元格:
<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>
如何激活此標簽以使其從 firebase 資料庫中洗掉,就像這樣:
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());
}
但我希望它用于標簽而不是 ImgButton 并希望在視圖模型頁面中激活它
uj5u.com熱心網友回復:
我希望它用于標簽而不是 ImgButton 并希望在視圖模型頁面中激活它
是的,您可以使用TapGestureRecognizerMVVM 來實作這一點。
根據您的代碼,我做了一個簡單的演示。您可以參考以下代碼:
<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";
}
}
注意:您可以根據您的要求修改上述代碼。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/466771.html
標籤:C# 火力基地 xamarin xamarin.forms
