Richard A
Richard A

Reputation: 191

How can I assign a color to a constant in Xamarin?

Here is what I am trying to do:

public static partial class Const
{

    public static class IconColors
    {
        public const Color  IconBlue1 = Color.FromHex("007AFF");
    }

}

But it gives me an error saying that the type Color cannot be declared const.

Does anyone have any suggestions / advice ?

Upvotes: 1

Views: 189

Answers (1)

Lucas Zhang
Lucas Zhang

Reputation: 18861

You could define it like following

public class IconColors
{
        public static Color IconBlue1 { get; } = Color.FromHex("007AFF");
}

And access it like

var color = IconColors.IconBlue1;

Upvotes: 1

Related Questions