C# 将值设置为dependency属性时发生TypeInitialization异常
我正在开发一个usercontrol,在其中注册依赖项属性,如下所示C# 将值设置为dependency属性时发生TypeInitialization异常,c#,xaml,windows-phone-8,C#,Xaml,Windows Phone 8,我正在开发一个usercontrol,在其中注册依赖项属性,如下所示 public string TextBoxHint { get { return (string)GetValue(TextBoxHintProperty); } set { SetValue(TextBoxHintProperty, value); } } public static readonly DependencyProperty TextBoxHin
public string TextBoxHint
{
get { return (string)GetValue(TextBoxHintProperty); }
set { SetValue(TextBoxHintProperty, value); }
}
public static readonly DependencyProperty TextBoxHintProperty =
DependencyProperty.Register("TextBoxHint",
typeof(string),
typeof(AutoCompleteBox),
new PropertyMetadata("Search"));
我在另一个页面中使用usercontrol,如下所示
<localControls:AutoCompleteBox TextBoxHint="Search Task" />
执行上述代码会导致SetValue()函数出现TypeInitialization异常
有人能指出代码有什么问题吗
提前感谢…依赖项属性需要该属性的SetValue和GetValue函数,所以应该是这样的
public string ToolTipText
{
get { return (string)this.GetValue(ToolTipTextProperty); }
set { this.SetValue(ToolTipTextProperty, value); }
}
public static object GetToolTipText(DependencyObject target)
{
return (object)target.GetValue(ToolTipTextProperty);
}
public static void SetToolTipText(DependencyObject target, Object value)
{
target.SetValue(ToolTipTextProperty, value);
}
public static readonly DependencyProperty ToolTipTextProperty = DependencyProperty.RegisterAttached("ToolTipText", typeof(string), typeof(Controls.ProgressSlider), new PropertyMetadata("0%"));
请发布更多关于例外情况的详细信息。任何内部异常也是如此。