zoukankan      html  css  js  c++  java
  • WPF System.InvalidCastException: 无法将类型为“System.Windows.Media.Color”的对象强制转换为类型“System.Windows.Media.Brush”。

    场景:添加ComboBox样式,界面卡死,日志异常文件如下:

    2018-04-08 20:07:44,641 | ERROR | System.InvalidCastException: 无法将类型为“System.Windows.Media.Color”的对象强制转换为类型“System.Windows.Media.Brush”。
       在 System.Windows.Shapes.Shape.get_Stroke()
       在 System.Windows.Shapes.Shape.get_IsPenNoOp()
       在 System.Windows.Shapes.Shape.GetPen()
       在 System.Windows.Shapes.Shape.GetNaturalSize()
       在 System.Windows.Shapes.Shape.MeasureOverride(Size constraint)
       在 System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       在 System.Windows.UIElement.Meas

    原因:将颜色值赋给Brush,错误代码如下:

    <Setter Property="BorderBrush" Value="{DynamicResource Blue5}" />

    解决方法:静态引用正确的样式,或者删除该代码。使用DynamicResource时一定要注意同名冲突。

  • 相关阅读:
    Redis
    Maven总结
    spring知识点总结
    网上好文搜集整理
    python 代码删除空目录
    plantUML使用指南
    python的基础操作
    八卦基础编程学习
    python历年入坑记录大全
    python实现的百度云自动下载
  • 原文地址:https://www.cnblogs.com/bincoding/p/8747154.html
Copyright © 2011-2022 走看看