WPF : Define binding's default

后端 未结 2 1159
清酒与你
清酒与你 2021-02-03 23:45

In WPF, I would like to be able to template how my bindings are applied by default.

For instance, I want to write :

Text=\"{Binding Path=PedigreeName}\"
         


        
2条回答
  •  情书的邮戳
    2021-02-04 00:29

    Use one of the overloads of DependencyProperty.Register that take a PropertyMetadata. Pass an instance of FrameworkPropertyMetadata and set its properties.

    public class Dog {
        public static readonly DependencyProperty PedigreeNameProperty =
            DependencyProperty.Register("PedigreeName", typeof(string), typeof(Dog),
                new FrameworkPropertyMetadata() {
                    BindsTwoWayByDefault = true,
                    DefaultUpdateSourceTrigger = UpdateSourceTrigger.LostFocus
                }
            );
    

    I don't offhand see a way to set the defaults for NotifyOnValidationError, ValidatesOnDataErrors, or ValidatesOnExceptions, but I haven't used this enough to be sure what to look for; they may be there.

提交回复
热议问题