绑定 WPF DependencyProperty 的默认设置
我创建了一个名为 MyCustomComboBox
的自定义用户控件。在应用程序的每个地方,我都会执行以下操作:
<Widgets:MyCustomComboBox
Foo="{Binding Foo,
UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />
MyCustomComboxBox 具有依赖属性 Foo
,我在组合框中有一些验证和其他逻辑,这就是我将其包装在自定义控件中的原因。
自定义组合框包含在另一个用户控件中,该控件也具有组合框绑定到的 Foo
属性。
但我还必须设置 UpdateSourceTrigger
和 Mode
,我想以某种方式指定这些是绑定到该 DependencyProperty 时的默认值。能做到吗?
I've created a custom user control named MyCustomComboBox
. Everywhere in the application I put it I do the following:
<Widgets:MyCustomComboBox
Foo="{Binding Foo,
UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />
MyCustomComboxBox has the dependency property Foo
, I have some validation and other logic in the combobox which is the very reason why I wrapped it up in a custom control.
The custom combobox is included another user control which also has a Foo
property, which the combobox's is bound to.
But I also have to set UpdateSourceTrigger
and Mode
, I would like to somehow specify that those are the default values when binding to that DependencyProperty. Can it be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以在依赖项属性元数据中指定默认的 BindingMode:
但是,据我所知,无法为更新源触发器提供默认值。
The default
BindingMode
can be specified in the dependency property metadata:However, to my knowledge there is no way to provide a default for the update source trigger.