Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove button's background color when pressed - xamarin forms UWP

I want to remove the button background color when it is pressed and like to have transparent background since I am using image as a background.
Able to remove the border while mouse hover by the following code:

btn.BorderThickness = new Thickness(0,0,0,0);
btn.Padding = new Thickness(0, 0, 0, 0);

and by setting:

btn.Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Transparent);

However I'm unable to remove the background while clicking on it, it is showing a gray colored background.
Any suggestions would be much appreciated.

like image 748
Sudha Avatar asked Jan 18 '16 18:01

Sudha


1 Answers

No matter what you set, the default template will (should) override your value due to the Pressed state of the CommonStates VisualStateGroup.

<VisualState x:Name="Pressed">
    <Storyboard>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootGrid"
                                       Storyboard.TargetProperty="Background">
            <!-- This will cause the gray background color of the button -->
            <DiscreteObjectKeyFrame
                KeyTime="0"
                Value="{ThemeResource SystemControlBackgroundBaseMediumLowBrush}" />
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>
</VisualState>

Instead of setting the color - as well as the border, how you're doing it right now - from code behind, you should create your own template for the buttons, setting the Background to the desired value, e.g. Transparent.

like image 51
Herdo Avatar answered Oct 11 '22 00:10

Herdo