ContentProperty를 "텍스트"로 설정하는 데 문제가 있습니다. 내가받은 오류는 다음과 같습니다.'Text'속성의 ContentPropertyAttribute가 올바르지 않습니다.
'MyType'유형의 유효하지 않은 ContentPropertyAttribute가 'Text'속성을 찾을 수 없습니다.
코드 뒤에 다음과 같습니다
실제로 내가하는 DependencyProperty 이외의 CLR 속성 뭔가 이름을 경우 작동하도록 가지고있다[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);
}
}
}
- 잘못 내가 사용하고 DependencyProperties?
죄송합니다. 그저 쉽게 따라 할 수 있도록 형식 이름을 정리했습니다. typeof (MyType)라고 가정합니다. –
"새 PropertyMetadata (false))"을 변경해야합니다. "new PropertyMetadata (null))"와 같은 문자열 값으로 변경합니다. – micahtan
실제로 GetText와 SetText를 제거하면 오류가 제거됩니다. – rmoore