Yes, you can conditionally enable or disable a command by implementing the CanExecute method. Here is an example:
bool CanSubmit = true; // Your condition or Boolean property
Button myButton = new Button
{
Text = "Submit",
};
myButton.Command = new Command(() =>
{
DisplayAlert("Button Clicked", "Button was clicked!", "OK");
}, () => CanSubmit);
Content = new StackLayout
{
Children = { myButton },
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand
};
Share with