Yes, you can transmit parameters to a command by using the CommandParameter property. Here is an example involving a parameter:
C#
Button myButton = new Button
{
Text = "Click Me",
Command = new Command((parameter) =>
{
string parameterValue = parameter as string;
if (!string.IsNullOrEmpty(parameterValue))
{
DisplayAlert(parameterValue, "Button was clicked!", "OK");
}
}),
CommandParameter = "Hello, .NET MAUI!"
};
var stackLayout = new StackLayout
{
Children = { myButton }
};
Content = stackLayout;
Share with