WPF用户控件抛出的设计时异常 [英] WPF user control throws design-time exception
本文介绍了WPF用户控件抛出的设计时异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有启动定时器一个用户控件。它看起来像XAML设计试图调用代码,它链接到一些后端数据库的东西。我一直在设计屏幕上得到一个unhanded异常错误。
任何想法我怎么能阻止设计师尝试运行的代码?
解决方案
在设计时加载XAML设计将调用用户控件的构造。
;为了避免这种情况,你可以为你的用户控件的构造函数
如果(System.ComponentModel.DesignMode)返回如下放置一个if条件
I have a userControl which starts a timer. It looks like the XAML designer is trying to call that code, which links to some back-end database stuff. I keep getting an unhanded exception error in the design screen.
Any ideas how I can stop the designer trying to run the code?
解决方案
XAML designer will call the UserControl's constructor when loading in designer. In order to avoid this you can place a if condition as follows in your UserControl constructor
if(System.ComponentModel.DesignMode) return;
这篇关于WPF用户控件抛出的设计时异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文