How to remove button background color when clicked - xamarin UWP form

I want to remove the background color of the button when pressed and as if I had a transparent background, since I use the image as the background. Ability to remove borders when hovering over the following code

targetButton.BorderThickness = new Thickness (0,0,0,0);

targetButton.Padding = new Thickness (0, 0, 0, 0);

and setting

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

but I can’t remove the background by clicking on it, it shows the gray color of the background. Any suggestions would be highly appreciated.

+5
source share
1 answer

No matter what you set, the default template will (should) override your value due to the state of Pressed 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, as you are doing right now - from the code behind, you should create your own button template by setting Background to the desired value, for example. Transparent

+5
source

Source: https://habr.com/ru/post/1240868/


All Articles