[英]How can I remove a color from a button in Xamarin?
In my C# I am changing to color of a button like this: 在我的C#中,我正在改变这样一个按钮的颜色:
aButton.BackgroundColor = Color.FromHex("#e9e9e9");
Is there a way to remove this color. 有没有办法去除这种颜色。 I know I could set it back to the color it was before but wondering if there is a way to just remove whatever was assigned?
我知道我可以把它恢复到以前的颜色,但想知道是否有办法删除任何分配的东西?
According to the Xamarin documentation, the BackgroundColor
of a VisualElement
is Color.Default
. 根据Xamarin文档,
VisualElement
的BackgroundColor
是Color.Default
。
So you can just assign your Button.BackgroundColor
property to Color.Default
: 所以你可以将
Button.BackgroundColor
属性分配给Color.Default
:
aButton.BackgroundColor = Color.Default;
For the sake of completeness: You can't remove a color because it is a non-nullable value type . 为了完整起见:您无法删除颜色,因为它是不可为空的值类型 。 If you instead intend to make it transparent, assign it to
Color.Transparent
: 如果您打算将其设为透明,请将其指定给
Color.Transparent
:
aButton.BackgroundColor = Color.Transparent;
You are changing the background colour of the Button
. 您正在更改
Button
的背景颜色。 there is no way to "remove" the colour. 没有办法“删除”颜色。 I don't think this exists in any language (someone correct me if I'm wrong)
我认为这不存在于任何语言中(如果我错了,有人会纠正我)
Your best bet is to reset the Colour: 你最好的办法是重置颜色:
public Color PreviousColour { get; set;}
public void SetColour()
{
PreviousColour = aButton.BackgroundColor;
aButton.BackgroundColor = Color.FromHex("#e9e9e9");
}
public void ResetColour()
{
aButton.BackgroundColor = PreviousColour;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.