【问题标题】:how to remove button's background color when pressed - xamarin forms UWP按下时如何删除按钮的背景颜色-xamarin形成UWP
【发布时间】:2016-04-24 01:17:29
【问题描述】:

我想在按下按钮时移除按钮的背景颜色,并且喜欢透明背景,因为我使用图像作为背景。
可以通过以下代码在鼠标悬停时移除边框:

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);

但是,我无法在单击背景时删除背景,它显示为灰色背景。
任何建议将不胜感激。

【问题讨论】:

  • 你试过targetButton.BackgroundColor = Color.Transparent

标签: xamarin xamarin.forms uwp


【解决方案1】:

无论您设置什么,由于CommonStatesVisualStateGroupPressed 状态,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.

【讨论】:

  • 是的,已经找到了,删除了故事板本身。不过谢谢
  • @Sudha 你可以批准一个答案,或者关闭问题:)
  • @Herdo 有没有办法通过样式等删除所有按钮的背景?
  • @Shimmy 当然,只需设置按钮的默认样式。
猜你喜欢
  • 1970-01-01
  • 2016-07-04
  • 2020-11-07
  • 1970-01-01
  • 1970-01-01
  • 2021-02-23
  • 2011-09-01
  • 2023-04-01
  • 2018-06-19
相关资源
最近更新 更多