我有一個用 xaml.cs 檔案撰寫的代碼,但我想在 viewmodel 檔案中執行此操作,但我不知道該怎么做,我嘗試執行命令,但這沒有用,我只是初學者,所以對這種模式和命令沒有太多想法
這是我的代碼:
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());
}
請問有什么幫助嗎?
uj5u.com熱心網友回復:
您可以為 ImageButton 系結命令。下面是一個簡單的代碼供您參考。
xml:
<ImageButton Command="{Binding ImgButtonCommand}"></ImageButton>
視圖模型:
public class Page1ViewModel
{
public Command ImgButtonCommand { get; set; }
public Page1ViewModel()
{
ImgButtonCommand = new Command(() =>
{
//something you want to do
});
}
}
頁面系結:
public partial class Page1 : ContentPage
{
public Page1()
{
InitializeComponent();
this.BindingContext=new Page1ViewModel();
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/465923.html
標籤:xamarin xamarin.forms 虚拟机 命令
