开发者

WPF Color from friendly name as string

开发者 https://www.devze.com 2023-03-02 17:49 出处:网络
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 su

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?


You can use the following code:

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

More information on ColorConverter can be found here.

0

精彩评论

暂无评论...
验证码 换一张
取 消