DataGridTextColumn에 사용자 지정 DataProperty를 추가하려고합니다.WPF : 사용자 지정 DependencyProperty에 바인딩 할 수 없습니다.
I'v은 사용자 정의 클래스를 상속하고 다음과 같이 종속성 속성을 추가 :
public class CustomDataGridTextColumn : DataGridTextColumn
{
public int MyProperty
{
get { return (int)GetValue(MyPropertyProperty); }
set { SetValue(MyPropertyProperty, value); }
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MyPropertyProperty =
DependencyProperty.Register("MyProperty", typeof(int), typeof(CustomDataGridTextColumn), new PropertyMetadata(0));
}
내가 바로 InitComponents() ;:
CustomDataGridTextColumn test = new CustomDataGridTextColumn()
{
Header = "1. Operand",
Binding = new Binding("Operand1") //<- This works
};
test.SetValue(CustomDataGridTextColumn.MyPropertyProperty, new Binding("Operand1")); // <- This doesn't
후 내 MainWindow를 생성자에 다음 코드와 바인딩 설정
내 응용 프로그램을 시작할 때 ""System.Windows.Data.Binding "속성"MyProperty ""에 대한 유효한 값이 아닙니다 "("참고 "test.SetValue (...)"에서 "System.ArgumentExcpetion" : "CS1324"와 같은 오류 코드가 없으므로이 오류 메시지는 나에 의해 번역됩니다.
필자는 모든 종속성 속성이 데이터 바인딩을 지원해야한다고 생각합니까? 비하인드 코드에서 바인딩을 설정하기 위해
내가이 뒤에 코드에서 수행해야 함을 언급하는 것을 잊었다. –