WPF:定义绑定的默认 [英] WPF : Define binding's default
本文介绍了WPF:定义绑定的默认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在WPF中,我希望能够模板我的绑定是如何被默认应用。
In WPF, I would like to be able to template how my bindings are applied by default.
比如说,我想要写:
Text="{Binding Path=PedigreeName}"
不过,这将是我仿佛类型:
But it would be as if I had typed :
Text="{Binding Path=PedigreeName, Mode=TwoWay, UpdateSourceTrigger=LostFocus, NotifyOnValidationError=True, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}"
任何想法?
谢谢,
- 帕特里克
推荐答案
在除了乔·怀特的很好的答案,你也可以创建一个从继承绑定,并设置您需要的默认属性值的类。例如:
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;
}
}
这篇关于WPF:定义绑定的默认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文