在 WPF 中,我希望能够对默认情况下应用绑定的方式进行模板化。
例如,我想写:
Text="{Binding Path=PedigreeName}"
但这就像我输入了:
Text="{Binding Path=PedigreeName, Mode=TwoWay, UpdateSourceTrigger=LostFocus, NotifyOnValidationError=True, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}"
任何想法 ?
Thanks,
使用以下重载之一依赖属性.寄存器 http://msdn.microsoft.com/en-us/library/system.windows.dependencyproperty.register.aspx需要一个 PropertyMetadata。传递一个实例框架属性元数据 http://msdn.microsoft.com/en-us/library/system.windows.frameworkpropertymetadata_properties.aspx并设置其属性。
public class Dog {
public static readonly DependencyProperty PedigreeNameProperty =
DependencyProperty.Register("PedigreeName", typeof(string), typeof(Dog),
new FrameworkPropertyMetadata() {
BindsTwoWayByDefault = true,
DefaultUpdateSourceTrigger = UpdateSourceTrigger.LostFocus
}
);
我没有立即找到一种方法来设置 NotifyOnValidationError、ValidatesOnDataErrors 或 ValidatesOnExceptions 的默认值,但我还没有充分使用它来确定要查找什么;他们可能在那里。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)