Hi all,
I've a button custom renderer. What i want is when the button is enabled, background = red. When disabled, background = gray.
Tried adding a button trigger but the backgroundcolor does not change. Even when i manually change the backgroundcolor it didn't change.
OnElementChanged is not called when background is set manually. is this a bug or am i doing something wrong?
btn.BackgroundColor = Color.FromHex("#e0e0e0");
AND
<l:TextButton x:Name="btn" Text="Add" Clicked="AddClicked" TextColor="White" BorderRadius="0">
<l:TextButton.Triggers>
<Trigger TargetType="Button" Property="IsEnabled" Value="True">
<Setter Property="BackgroundColor" Value="Red" />
</Trigger>
<Trigger TargetType="Button" Property="IsEnabled" Value="False">
<Setter Property="BackgroundColor" Value="Gray" />
</Trigger>
</l:TextButton.Triggers>
</l:TextButton>
This is my custom renderer
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e)
{
base.OnElementChanged(e);
if (Control != null)
{
GradientDrawable gdDefault = new GradientDrawable();
var elem = (TextButton)this.Element;
gdDefault.SetColor(elem.BackgroundColor.ToAndroid());
.......
.......
}
Please help! Thank you.