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

How to change the background color of a button when the mouse is over or is pressed in Xamarin.Forms

$
0
0

I have tried to use Custom Renderer but I can not change the background of the button in uwp, it is always gray. This is what I have done:

public class MyButtonRenderer : ButtonRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
    {
        base.OnElementChanged(e);

        if (Control != null)
        {
            Control.Foreground = new SolidColorBrush(Colors.Black);
            Control.BackgroundColor = new SolidColorBrush(Colors.White);
            Control.Background = new SolidColorBrush(Colors.White);
        }
    }

    protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        base.OnElementPropertyChanged(sender, e);
        Control.Foreground = new SolidColorBrush(Colors.Black);
        Control.BackgroundColor = new SolidColorBrush(Colors.White);
        Control.Background = new SolidColorBrush(Colors.White);
    }

}

Any clue or suggestion?

Thanks;


Viewing all articles
Browse latest Browse all 77050

Trending Articles