Hello,
Welcome to our Microsoft Q&A platform!
You can bind a property to your Botton's BackgroundColor. I add a following property.
Color _BTNbackground = Color.Red;
public Color BTNbackground
{
get
{
return _BTNbackground;
}
set
{
if (_BTNbackground != value)
{
_BTNbackground = value;
OnPropertyChanged("BTNbackground");
}
}
}
Then I add it to Button in the XAML.
<Button Text="click" BackgroundColor="{Binding BTNbackground}" Command="{Binding TestCommand}"></Button>
When you need to change the background color of Button, you can set it directly.
public bool IsEditing
{
get
{
return _isEditing;
}
set
{
if (_isEditing != value)
{
if (_isEditing)
{
BTNbackground = Color.Yellow;
}
else
{
BTNbackground = Color.AliceBlue;
}
_isEditing = value;
OnPropertyChanged("IsEditing");
}
}
}
I use a Button to change the value of IsEditing
, if the IsEditing
value is true. Button's background to Yellow, if the IsEditing
value is false . Button's background to AliceBlue,
private void Button_Clicked(object sender, EventArgs e)
{
IsEditing = !IsEditing;
}
When canExecute
true false, we can change the backgroundColor as normal. Here is running screenshot.
Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
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.