Forum Xamarin.Forms


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Button Background Color not changing

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");


<l:TextButton x:Name="btn" Text="Add" Clicked="AddClicked" TextColor="White" BorderRadius="0">
              <Trigger TargetType="Button" Property="IsEnabled" Value="True">
                <Setter Property="BackgroundColor" Value="Red" />
              <Trigger TargetType="Button" Property="IsEnabled" Value="False">
                <Setter Property="BackgroundColor" Value="Gray" />

This is my custom renderer

    protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e)
        if (Control != null)
            GradientDrawable gdDefault = new GradientDrawable(); 

            var elem = (TextButton)this.Element;

Please help! Thank you.

Best Answer


  • CeedoubleyouCeedoubleyou USMember ✭✭

    Thank you Felipe. Its working now.

Sign In or Register to comment.