原文地址:http://www.silverlightchina.net/html/tips/2010/0806/1695.html

用Blend 或VS 2010的设计视图打开一个用户控件,如果出现错误(最常见的是空引用错误),而debug时程序运行正常,那很可能是由于设计时的一些限制造成控件无法在设计器中正常打开。如何避免呢?通过 System.ComponentModel.DesignerProperties.IsInDesignTool 判断当前状态是否是设计时,在设计时避免构造函数与Loaded事件处理方法中执行那些代码即可,例如:

View Code
 1 public partial class 
 2 ProductsView : UserControl 
 3 {
 4     public ProductsView() {
 5         InitializeComponent();
 6         if (!DesignerProperties.IsInDesignTool) 
 7         {
 8             /*
 9               访问webservice等操作
10             */
11         }
12     }
13 }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2021-10-15
  • 2022-12-23
  • 2021-08-19
  • 2021-12-30
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-06
  • 2022-12-23
  • 2021-09-13
  • 2021-06-29
  • 2022-12-23
相关资源
相似解决方案