Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Button Background Color not changing

$
0
0

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.


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>