List All Windows C# WPF Colors

FEBRUARY 4, 2020

There's a full list of colors in Windows C# .NET Framework to be used with WPF and XAML components, both accessible through System.Windows.Media.Colors and System.Drawing.KnownColor. These are their names.

AliceBlue, AntiqueWhite, Aqua, Aquamarine, Azure, Beige, Bisque, Black, BlanchedAlmond, Blue, BlueViolet, Brown, BurlyWood, CadetBlue, Chartreuse, Chocolate, Coral, CornflowerBlue, Cornsilk, Crimson, Cyan, DarkBlue, DarkCyan, DarkGoldenrod, DarkGray, DarkGreen, DarkKhaki, DarkMagenta, DarkOliveGreen, DarkOrange, DarkOrchid, DarkRed, DarkSalmon, DarkSeaGreen, DarkSlateBlue, DarkSlateGray, DarkTurquoise, DarkViolet, DeepPink, DeepSkyBlue, DimGray, DodgerBlue, Firebrick, FloralWhite, ForestGreen, Fuchsia, Gainsboro, GhostWhite, Gold, Goldenrod, Gray, Green, GreenYellow, Honeydew, HotPink, IndianRed, Indigo, Ivory, Khaki, Lavender, LavenderBlush, LawnGreen, LemonChiffon, LightBlue, LightCoral, LightCyan, LightGoldenrodYellow, LightGray, LightGreen, LightPink, LightSalmon, LightSeaGreen, LightSkyBlue, LightSlateGray, LightSteelBlue, LightYellow, Lime, LimeGreen, Linen, Magenta, Maroon, MediumAquamarine, MediumBlue, MediumOrchid, MediumPurple, MediumSeaGreen, MediumSlateBlue, MediumSpringGreen, MediumTurquoise, MediumVioletRed, MidnightBlue, MintCream, MistyRose, Moccasin, NavajoWhite, Navy, OldLace, Olive, OliveDrab, Orange, OrangeRed, Orchid, PaleGoldenrod, PaleGreen, PaleTurquoise, PaleVioletRed, PapayaWhip, PeachPuff, Peru, Pink, Plum, PowderBlue, Purple, Red, RosyBrown, RoyalBlue, SaddleBrown, Salmon, SandyBrown, SeaGreen, SeaShell, Sienna, Silver, SkyBlue, SlateBlue, SlateGray, Snow, SpringGreen, SteelBlue, Tan, Teal, Thistle, Tomato, Turquoise, Violet, Wheat, White, WhiteSmoke, Yellow, YellowGreen

And here's a function that returns a string list—List<string>—with all color names as strings.

/// <summary>
/// Get a list of all Windows colors
/// </summary>
/// <returns></returns>
public static List<string> Colors()
{
    // Create empty list
    List<string> colorList = new List<string>();

    // Get type of KnownColor enum
    var color = typeof(System.Drawing.KnownColor);

    // Enumerate all known color names in enum
    var colors = Enum.GetValues(color);

    // Remove 27 from beginning
    var from = 27;

    // Remove 7 elements from the end
    var to = colors.Length - 7;

    // Only keep color names and not user interface colors
    for (int i = from; i < to; i++)
    {
        colorList.Add(colors.GetValue(i).ToString());
    }

    // Return filtered color list
    return colorList;
}

You can then use one of the colors by its string name.

// Use 19th color
// System.Windows.Media.ColorConverter
var color = ColorConverter.ConvertFromString(colors[19]);

Having the entire list is useful to randomly select colors or to iterate through them. If you have an index and you want to use this list (or a shorter list) and start again when you run out of colors, you can do this.

// System.Windows.Media.ColorConverter
var color = ColorConverter.ConvertFromString(colors[index % colors.Count]);

You could also use a color with its string name, directly.

// System.Windows.Media.ColorConverter
var color = ColorConverter.ConvertFromString("Crimson");

And, lastly, you can cherry-pick and tailor your own custom Color list and use the same calls as before.

public static List<string> colors = new List<string>() {
    "Crimson",
    "MediumSeaGreen",
    "CornflowerBlue",
    "Peru",
    "Coral",
    "SlateGray",
    "Firebrick",
    "Sienna",
    "Teal",
    "Orange",
    "OrangeRed",
};

Before you go

If you found this useful, you might want to join my mailing lists; or take a look at other posts about code, C#, TypeScript, and React.