컨트롤을 사용하는 코드에서 값을 설정하려는 레이블을 포함하는 기본 WPF/Silverlight 사용자 정의 컨트롤 코드가 있습니다. 종속성 속성 및 관련 이벤트의 정의에 대한 요구 사항을 단순화하는 방법이 있습니까? 간단한 코딩 작업 (속성, 방법 및 관련 배선) 인 것처럼 보이는 것은 매우 시끄러운 것처럼 보입니다.WPF 및 Silverlight에서 종속성 속성 설치를 단순화하는 방법이 있습니까?
private static DependencyProperty CountProperty;
public MyWpfUserControl()
{
InitializeComponent();
PropertyChangedCallback countChangedCallback = CountChanged;
var metaData = new PropertyMetadata(countChangedCallback);
CountProperty = DependencyProperty.Register("Count", typeof (int), typeof (MyWpfUserControl), metaData);
}
public int ItemsCount
{
get { return (int) GetValue(CountProperty); }
set { SetValue(CountProperty, value); }
}
private void CountChanged(DependencyObject property,
DependencyPropertyChangedEventArgs args)
{
// Set the value of another control to this property
label1.Content = ItemsCount;
}
'propdp'를 입력하고 코드의 아무 곳에서나 Tab 키를 두 번 누릅니다. 또한'CountChanged' 속성은 정적 이어야만합니다. – vorrtex