C#String类型转换成Brush类型:

using System.Windows.Media;

BrushConverter brushConverter = new BrushConverter();
Brush brush = (Brush)brushConverter.ConvertFromString(“#cacaca”);

注意:

using System.Windows.Media;时如果出现错误,是因为没有引入PresentationCore
解决方案资源管理器->右击引用->添加引用->程序集->框架->勾选PresentationCore->点击确认。

此方法不建议,会与using System.Drawing;中的部分方法冲突。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2021-11-05
  • 2021-12-26
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案