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

-- ::, | 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时一定要注意同名冲突。

WPF System.InvalidCastException: 无法将类型为“System.Windows.Media.Color”的对象强制转换为类型“System.Windows.Media.Brush”。的更多相关文章

  1. 无法将类型为“System.Windows.Controls.SelectedItemCollection”的对象强制转换为类型“System.Collections.Generic.IList`1

    在WPF中DataGrid 选择事件中获取SelectedItems 报错如下 无法将类型为“System.Windows.Controls.SelectedItemCollection”的对象强制转 ...

  2. 【Winform】 无法将类型为“System.Windows.Forms.SplitContainer”的对象强制转换为类型“System.ComponentModel.ISupportInitialize”。

    问题:将dotnet framework 4.0 切换到2.0时,编译没有问题,在运行时出现如下错误:System.InvalidCastException: 无法将类型为“System.Window ...

  3. .net4.0切换2.0时,SplitContainer”的对象强制转换为类型

    问 题:将dotnet framework 4.0 切换到2.0时,编译没有问题,在运行时出现如下错误:System.InvalidCastException: 无法将类型为“System.Windo ...

  4. Web Service接口返回泛型的问题(System.InvalidCastException: 无法将类型为“System.Collections.Generic.List`1[System.String]”的对象强制转换为类型“System.String[]”)

    在使用C#写Web Service时遇到了个很奇怪的问题.返回值的类型是泛型(我用的是类似List<string>)的接口,测试时发现总是报什么无法转换为对象的错误,百思不得其解. 后来在 ...

  5. 无法将类型为“System.Decimal”的对象强制转换为类型“System.Char[]”。

    在用微软的SSIS操作ORACLE 数据源的时候碰到以下报错信息: [ADO NET Destination [13455]] 错误: 数据插入期间出现异常,从提供程序返回的消息为:无法将类型为&qu ...

  6. 无法将类型为“System.DBNull”的对象强制转换为类型“System.String”

    在ERP中做业务类单据,有时候会遇到这样的报错. 无法将类型为"System.DBNull"的对象强制转换为类型"System.String"   去数据库中检 ...

  7. 保存图片控件上的图片到本地 出现错误:无法将类型为“System.Windows.Media.Imaging.BitmapFrameDecode”的对象强制转换为类型“System.Windows.Media.Imaging.BitmapImage”。

    保存图片控件上的图片到本地 出现错误:无法将类型为“System.Windows.Media.Imaging.BitmapFrameDecode”的对象强制转换为类型“System.Windows.M ...

  8. C# 无法将类型为“__DynamicallyInvokableAttribute”的对象强制转换为类型...

    错误代码: //遍历方法特性 foreach (MethodInfo m in type.GetMethods()) { foreach(Attribute a in m.GetCustomAttri ...

  9. 如何解决”无法将类型为“System.DateTime”的对象强制转换为类型“System.String”。“

    字段Time在数据库中为datetime类型 dr.GetString(3).ToString() dr.GetString(3).ToString() => dr.GetDateTime(3) ...

随机推荐

  1. iOS Terminating app due to uncaught exception &#39;NSInternalInconsistencyException&#39;, reason: &#39;unable to

    刚接触iOS,依照教程操作执行出现错误 Terminating app due to uncaught exception 'NSInternalInconsistencyException', re ...

  2. Linux shell下30个有趣的命令

    Tips 原文作者:Víctor López Ferrando 原文地址:30 interesting commands for the Linux shell 这些是我收集了多年的Linux she ...

  3. FreeSWITCH收到重复的DTMF信号

    一.背景 用户是运营商手机,拨打的是运营商的固话号码进入的FreeSWITCH的IVR,进入IVR语音播报后,按指定的分机号呼相关人员. 二.现象 用户反映拨打124870找不到指定人员,以前是正常的 ...

  4. stm8时钟

    为使系统快速启动,复位后时钟控制器自动使用HSI的8分频(HSI/8)做为主时钟(2M).其原因为HSI的稳定时间短,而8分频可保证系统在较差的VDD条件下安全启动.一旦主时钟源稳定,用户程序可将主时 ...

  5. android中碰撞屏幕边界反弹问题

    其实碰撞问题只是涉及到一点小算法而已,但在实际应用,尤其游戏中有可能会遇到,下面给出一个小示例,代码如下: MainActivity: package com.lovo; import android ...

  6. jmeter 的java请求代码在main方法里面执行

    1.新建一个java请求执行加法类 public class TestDemo { public int Tdemo(int a,int b){ int sum = 0; sum = a+b; ret ...

  7. 微信小程序 template添加点击事件

    介绍template是微信小程序提供的模板,可以在模板中定义代码片段,然后在不同的地方调用. 简单使用定义template因为项目中可能会需要到不止一个template,所以最好新建一个文件夹来存放t ...

  8. Android 3.0开始引入fragments(碎片、片段)类

    Fragment要点 Fragment作为Activity界面的一部分组成出现. 可以在一个Activity中同时出现多个Fragment,并且,一个Fragment亦可在多个Activity中使用. ...

  9. Android入门-新手如何成功创建一个Android小应用

    原文:http://android.eoe.cn/topic/summary 第一课程:Building Your First App [本课内容简介]欢迎加入到安卓应用的开发大潮中!这门课程会教授你 ...

  10. Android App开发技能图谱(转载)

    操作系统 Windows/MacOSX/Linux 编程语言 Java HTML/JS (Hybrid/Web App) C/C++ (NDK) SQL (DB) Kotlin 开发工具 IDE An ...