如何转换像“Red"这样的字符串?到 System.Windows.Media.Color? [英] How do I convert a string like "Red" to a System.Windows.Media.Color?
本文介绍了如何转换像“Red"这样的字符串?到 System.Windows.Media.Color?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我可以通过...走很长的路
I know I can go the long route by...
- 添加对 System.Drawing 的引用
- 从字符串创建 System.Drawing.Color
- 根据 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屋!
查看全文