Hello,
You are using [RelayCommand], it's a third-party tool feature and not supported on Q&A. Please see Commanding - .NET MAUI | Microsoft Learn.
I want to pass the Id of the viewmodel class as a commandparameter using a popup.
You can refer to the following code:
ViewModel (Adding ID property of the viewmodel class)
public class PayerEditViewModel
{
public string ID { get; set; }// ID property
public ICommand UpdateUdfCommand { private set; get; }
public PayerEditViewModel()
{
UpdateUdfCommand = new Command<String>(UpdateUdf);
}
private void UpdateUdf(String ID)
{// commandparameter
}
}
XAML of EditUserDefinedFieldPopupView
<VerticalStackLayout>
<Button Text= "OK" Command="{Binding UpdateUdfCommand}" CommandParameter="{Binding ID}" />
</VerticalStackLayout>
Code Behind
public EditUserDefinedFieldPopupView(PayerEditViewModel vm)
{
InitializeComponent();
this.BindingContext = vm;
}
Presenting this Popup in MainPage
private void OnCounterClicked(object sender, EventArgs e)
{
var ViewModel = new PayerEditViewModel();
ViewModel.ID = "111";
var popup = new EditUserDefinedFieldPopupView(ViewModel);
this.ShowPopup(popup);// then you could click the "OK" button to check if "111" has been passed
}
Best Regards,
Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.