什么是各种WPF绑定模式? [英] What are the various WPF binding modes?
本文介绍了什么是各种WPF绑定模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不明白WPF中的各种数据绑定模式,例如:
I do not understand the various data binding modes in WPF, such as:
- 单向
- 双向
- 一次性
- 等...
- One-Way
- Two-Way
- One-Time
- etc...
这些模式是什么意思?
应该什么时候使用?
推荐答案
-
OneWay
您希望bound属性更新用户界面。 -
TwoWay
:这与OneWay的行为相同
和OneWayToSource
组合。绑定属性将更新用户界面,并且用户界面中的更改将更新绑定属性(您将使用TextBox
或复选框
。 -
OneTime
:这与OneWay的行为相同
,只会更新一次用户界面。这应该是您默认的绑定选择(由于各种原因我将不会在这里详细说明),如果您实际需要额外的功能,您应该只使用其他类型的绑定。 -
OneWayToSource
:这与OneWay
相反 - 用户界面值更改更新绑定属性。 OneWay
: Use this when you want the bound property to update the user interface.TwoWay
: This has the same behavior asOneWay
andOneWayToSource
combined. The bound property will update the user interface, and changes in the user interface will update the bound property (You would use this with aTextBox
or aCheckbox
for example.)OneTime
: This has the same behavior asOneWay
except it will only update the user interface one time. This should be your default choice for binding (for various reasons I won't elaborate on here), you should only use other types of bindings if you actually need the extra functionality.OneWayToSource
: This is the opposite ofOneWay
-- user interface value changes update the bound property.
如果您没有指定任何内容,那么行为将取决于您使用的控件。
If you don't specify anything, then the behavior will depend on the control that you are using.
有关详细信息,请参阅 BindingMode
枚举MSDN 。
For more info, see BindingMode
enum on MSDN.
这篇关于什么是各种WPF绑定模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文