这里是我的OnApplyTemplate
的样子:检测设计模式“OnApplyTemplate”方法 - 自定义的控制
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
if (DesignerProperties.IsInDesignTool) return;
this.partTextBox = this.GetTemplateChild(PartTextBox) as TextBox;
this.partButton = this.GetTemplateChild(PartButton) as Button;
if (this.partTextBox == null || this.partButton == null)
{
throw new NullReferenceException("Template part(s) not available");
}
this.partTextBox.LostFocus += this.OnTextBoxLostFocus;
this.partButton.Click += this.OnButtonClick;
if (this.DataProvider == null)
{
throw new NotSupportedException("DataProvider wasn't specified");
}
第二行,我检查IsInDesignTool给我的错误,说我不能访问内部类“DesignerProperties”这里。
基本上,当我将控件从工具栏拖动到设计视图中时会发生异常,因为未指定DataProvider。所以,我需要禁用此代码的设计时间。
我该怎么做?
是的,这工作!我检查了 - 有4个!可能的DesignerProperties! – katit