Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Color from friendly name as string

Tags:

.net

wpf

Let's say I have a string object "AliceBlue", and I want to create the equivalent System.Windows.Media.Color object based on the Colors.AliceBlue static member. Does the WPF APIs support this directly, or would I have to use reflection to inspect the Colors class and pull out the correct static member?

like image 861
RationalGeek Avatar asked May 03 '11 12:05

RationalGeek


1 Answers

You can use the following code:

Color color = (Color)ColorConverter.ConvertFromString("AliceBlue");

More information on ColorConverter can be found here.

like image 76
CodeNaked Avatar answered Oct 20 '22 13:10

CodeNaked