2017-01-17 5 views
1

내 사용자 지정 DependencyProperty에 대해 ValidatesOnDataErrors를 True로 설정하는 방법이 있습니까? 그렇기 때문에 바인딩 할 때마다 그렇게 할 필요가 없습니까? this 줄에 무엇인가가 있습니다.사용자 지정 종속성 속성의 기본 ValidatesOnDataErrors를 지정하는 방법이 있습니까?

public static readonly DependencyProperty TextProperty = 
     DependencyProperty.Register(nameof(Text), typeof(string), 
      typeof(ErrorTextEdit), new FrameworkPropertyMetadata(null) 
      { 
       BindsTwoWayByDefault = true, 
       DefaultUpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, 
       // Something Here maybe??? 
      }); 

    public string Text 
    { 
     get { return (string) GetValue(TextProperty); } 
     set { SetValue(TextProperty, value); } 
    } 

내 컨트롤 또한 도움이 될 경우 TextBox에서 상속받을 수 있습니다.

답변

3

아니요, 두렵습니다. 이 속성은 종속성 속성이 아니라 Binding 클래스의 속성입니다.

How can i change the default values of the Binding Option in WPF?

또는 사용자 정의 바인딩 클래스 생성 :

public class CustomBinding : Binding 
{ 
    public CustomBinding(string path) 
     :base(path) 
    { 
     this.NotifyOnValidationError = true; 
    } 
} 
을 당신은 무엇을 위해 할 수있는 것은 당신을 위해 ValidatesOnDataErrors 속성을 설정하는 사용자 정의 태그 확장하여 XAML 마크 업에서 {Binding} 태그 확장을 대체하는 것입니다

사용법 :

<TextBlock Text="{local:CustomBinding Name}" /> 
+0

이것은 내가 생각하지 않은 매우 우아한 방법 중 하나입니다. – gajo357