Reputation: 51084
I want to take a string like "Green" and get the Color
type property of Colors
that is named "Green", but I just can't figure how.
InvokeMember
requires an object instance to invoke the named member on, but all the Color
properties of Colors
are static, and not available on an instance of Colors
.
Upvotes: 2
Views: 127
Reputation: 23107
Is it what you need?
var color = (Color)ColorConverter.ConvertFromString("Green");
it gets color by name using ColorConverter from Windows.Media
. It is equivalent to:
var color = Color.Green;
Upvotes: 1