Reputation: 375
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.
Upvotes: 6
Views: 5330
Reputation: 6046
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
.
Upvotes: 6