1
TextBox에서 파생 된 MyTextBox가 있습니다. 바인딩 옵션을 설정하고 싶습니다. ValidatesOnDataErrors = MyTextBox의 TextProperty True로 설정하면이 컨트롤을 사용할 때마다 ValidatesOnDataErrors가 True로 초기화됩니다.기본 클래스에서 기본 바인딩 옵션을 설정하는 방법이 있습니까?
이 내 코드입니다 :
public class MyTextBox:MyBaseTextBox
{
public MyTextBox()
{
MaxLength = 45;
}
protected override void OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
if (e.Property == TextProperty)
{
Binding b = BindingOperations.GetBinding(this, TextProperty);
if (b != null)
{
b.ValidatesOnDataErrors = true;
}
}
}
}
그리고 난 항상 예외를 얻을 :
An unhandled exception of type 'System.InvalidOperationException' occurred in PresentationFramework.dll
Additional information: Binding cannot be changed after it has been used.
내가 뭔가를 놓치고 있습니까?