Hello,
How can I use Trigger and Setter for a Button to change the BackgroundColor based on it's IsEnabled so if IsEnabled is True then the Background is Navy otherwise it's LightGray?
You can add two <Trigger> in <Button.Triggers>
, when IsEnabled
Property= true, set the background color to Navy. when IsEnabled
Property= false, set the background color to LightGray.
<Button Text="test" IsEnabled="False" >
<Button.Triggers>
<Trigger TargetType="Button"
Property="IsEnabled" Value="True">
<Setter Property="BackgroundColor" Value="Navy" />
</Trigger>
<Trigger TargetType="Button"
Property="IsEnabled" Value="False">
<Setter Property="BackgroundColor" Value="LightGray" />
</Trigger>
</Button.Triggers>
</Button>
Here is a official article about the Xamarin.Forms Triggers, you can refer to it.
Best Regards,
Leon Lu
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.