如何在按下时删除按钮的背景颜色 - xamarin 形成 UWP
how to remove button's background color when pressed - xamarin forms UWP
我想在按下按钮时删除按钮背景颜色,并且希望有透明背景,因为我使用图像作为背景。
可通过以下代码实现鼠标悬停时去除边框:
btn.BorderThickness = new Thickness(0,0,0,0);
btn.Padding = new Thickness(0, 0, 0, 0);
并通过设置:
btn.Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Transparent);
但是我无法在单击它时删除背景,它显示的是灰色背景。
任何建议将不胜感激。
无论您设置什么,由于 CommonStates
VisualStateGroup
.[=17= 的 Pressed
状态,default template 将(应该)覆盖您的值]
<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>
而不是设置颜色 - 以及边框,你现在是怎么做的 - 从后面的代码,你应该为按钮创建自己的模板,将 Background
设置为所需的值,例如Transparent
.
我想在按下按钮时删除按钮背景颜色,并且希望有透明背景,因为我使用图像作为背景。
可通过以下代码实现鼠标悬停时去除边框:
btn.BorderThickness = new Thickness(0,0,0,0);
btn.Padding = new Thickness(0, 0, 0, 0);
并通过设置:
btn.Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Transparent);
但是我无法在单击它时删除背景,它显示的是灰色背景。
任何建议将不胜感激。
无论您设置什么,由于 CommonStates
VisualStateGroup
.[=17= 的 Pressed
状态,default template 将(应该)覆盖您的值]
<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>
而不是设置颜色 - 以及边框,你现在是怎么做的 - 从后面的代码,你应该为按钮创建自己的模板,将 Background
设置为所需的值,例如Transparent
.