简体   繁体   English

如何从Xamarin中的按钮中删除颜色?

[英]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文档, VisualElementBackgroundColorColor.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.

相关问题 在 Xamarin 中,如何在 1 秒内更改按钮的背景颜色并再次将其恢复为原始颜色? - In Xamarin, how can I change the background color of a button for just 1 second and return it again to its original color? 如何在Xamarin android中从按钮下载(从URL)apk? - How can i download(from URL) an apk with a button in xamarin android? Xamarin:如何更改代码中添加的按钮的颜色? - Xamarin: how do I change the color of a button added in code? 如何删除按钮边框的颜色或/和控制其行为? - How can I remove my button's border's color or/and control its behavior? 如何在Xamarin.Forms中单击按钮时从地图上删除折线 - How to remove polyline from the map on button click in Xamarin.Forms 如何从Xamarin Forms for Android中的按钮视图中删除额外的填充? - How to remove extra padding from button views in Xamarin Forms for Android? 如何从单选按钮删除禁用的效果? - How can I remove disabled effect from Radio Button? 如何从特定的招摇文档中删除“授权”按钮? - How can I remove the 'Authorize' button from a particular swagger doc? 如何更改 xamarin 中的 PlaceHolder 文本颜色? - how can i change the PlaceHolder Text color in xamarin? Xamarin 如果包含减号,我如何更改 label 文本颜色 - Xamarin How can i change label text color if it contains minus
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM