如何转换像“Red"这样的字符串?到 System.Windows.Media.Color? [英] How do I convert a string like "Red" to a System.Windows.Media.Color?

查看:26
本文介绍了如何转换像“Red"这样的字符串?到 System.Windows.Media.Color?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以通过...走很长的路

I know I can go the long route by...

  1. 添加对 System.Drawing 的引用
  2. 从字符串创建 System.Drawing.Color
  3. 根据 System.Drawing.Color 的 ARGB 值创建 System.Windows.Media.Color.

但这感觉像是严重的矫枉过正.

But this feels like serious overkill.

有没有更简单的方法?

推荐答案

var color = (Color)ColorConverter.ConvertFromString("Red");

这篇关于如何转换像“Red"这样的字符串?到 System.Windows.Media.Color?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆