WPF : Define binding's default

后端 未结 2 1187
清酒与你
清酒与你 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:43

    In addition to Joe White's good answer, you could also create a class that inherits from Binding and sets the default property values you need. For instance :

    public class TwoWayBinding : Binding
    {
        public TwoWayBinding()
        {
            Initialize();
        }
    
        public TwoWayBinding(string path)
          : base(path)
        {
            Initialize();
        }
    
        private void Initialize()
        {
            this.Mode = BindingMode.TwoWay;
        }
    }
    

提交回复
热议问题