我无法将我的ContentProperty设置为“文本”。我给出的错误是:属性“文本”中的ContentPropertyAttribute无效
'MyType'类型的属性'Text'找不到ContentPropertyAttribute。
后面的代码看起来是这样的:
[ContentProperty("Text")]
public partial class MyType: UserControl
{
public MyType()
{
InitializeComponent();
}
public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text",
typeof (string),
typeof(MyType)));
public static string GetText(DependencyObject d)
{
return (string) d.GetValue(TextProperty);
}
public static void SetText(DependencyObject d, string value)
{
d.SetValue(TextProperty, value);
}
public string Text
{
get
{
return (string)GetValue(TextProperty);
}
set
{
SetValue(TextProperty, value);
}
}
}
其实我已经知道了,如果我的名字比其他的DependencyProperty的CLR属性的东西的工作 - 我使用DependencyProperties不正确?
对不起,这只是我清理类型名称,使其更容易遵循。假设它说typeof(MyType)。 – 2009-06-25 04:03:36
您需要更改“new PropertyMetadata(false));”为一个字符串值,如“new PropertyMetadata(null));” – micahtan 2009-06-25 04:10:55