本文介绍了有哪些 WPF 绑定模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
看不懂WPF中的各种数据绑定方式,比如:
I do not understand the various data binding modes in WPF, such as:
- 单向
- 双向
- 一次性
- 等等...
这些模式分别是什么意思?
What does each of these modes mean?
什么时候应该使用它们?
When should they be used?
推荐答案
OneWay
:当您希望绑定属性更新用户界面时使用此方法.TwoWay
:这与OneWay
和OneWayToSource
组合具有相同的行为.绑定属性将更新用户界面,用户界面中的更改将更新绑定属性(例如,您可以将其与TextBox
或Checkbox
一起使用.)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 枚举="noreferrer">Microsoft 文档.
For more info, see BindingMode
enum on Microsoft Docs.
这篇关于有哪些 WPF 绑定模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!