How to convert from System.Drawing.Color to System.Windows.Media.Color?

You can see examples of both of the conversion directions below:

Drawing.Color to Windows.Media.Color

// This is your color to convert from
System.Drawing.Color color; 
System.Windows.Media.Color newColor = System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B);

Windows.Media.Color to Drawing.Color

// This is your color to convert from
System.Windows.Media.Color color; 
System.Drawing.Color newColor = System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B);

For frequent use i suggest helper like this:

using SDColor = System.Drawing.Color;
using SWMColor = System.Windows.Media.Color;

namespace ColorHelper
{
    public static class ColorExt
    {
        public static SWMColor ToSWMColor(this SDColor color) => SWMColor.FromArgb(color.A, color.R, color.G, color.B);
        public static SDColor ToSDColor(this SWMColor color) => SDColor.FromArgb(color.A, color.R, color.G, color.B);
    }
}

Tags:

C#

Colors