I have the following style
<Style x:Key="GreenButtonStyle" BasedOn="{StaticResource MyButtonBaseStyle}" TargetType="Button">
<Style.Triggers>
<Trigger TargetType="Button" Property="IsEnabled" Value="False">
<Setter Property="BackgroundColor" Value="Silver" />
<Setter Property="TextColor" Value="Black" />
</Trigger>
<Trigger TargetType="Button" Property="IsEnabled" Value="True">
<Setter Property="BackgroundColor" Value="Green" />
<Setter Property="TextColor" Value="Orange" />
</Trigger>
</Style.Triggers>
</Style>
Which I use in the following view.
<Button x:Name="ConfirmButton"
Text="Confirm"
Style="{StaticResource GreenButtonStyle}"
IsEnabled="{Binding Source={x:Reference Some}, Path=ConfirmEnabled}"
/>
<Button x:Name="ToggleButton"
Text="Toggle"
Clicked="Toggle_Clicked"
/>
With the code behind (just snippets)
public partial class SomeView : ContentPage, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private bool _confirmEnabled = false;
public bool ConfirmEnabled
{
get { return _confirmEnabled; }
}
private void Toggle_Clicked(object sender, EventArgs e)
{
_confirmEnabled = !_confirmEnabled;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(ConfirmEnabled)));
}
}
When the View comes into play, everything is ok with the button inactive. When I click the toggle button, the font changes color to Orange as intended, but the background doesn't change color to green.
If I click the toggle twice (disable then enable) the font is Orange and background is finally green.
Anybody have any idea why the background color isn't changed on the first change of ConfirmEnabled to true?
Ended with implementing my own button control which is basically two buttons on top of each other and then depending on if it's enabled or disabled I hide or show the other one.
And the code behind