单向绑定 [英] One-way binding
问题描述
我知道这个问题存在,但是我找不到答案.
I know this question exists but I can't find the solution in the answers.
我有一个表单,该表单具有与自定义类的数据绑定,因此在更改表单时,将通知自定义类(永远不会发生逆向操作).
I have a form with a data-binding to a custom class so that when changing the form, the custom class gets notified (the inverse will never happen).
myForm.DataBindings.Add("Items", ItemsController.Singleton, "Items", false,
DataSourceUpdateMode.OnPropertyChanged);
现在发生的是,当我创建表单的实例并为Items属性设置一些值时,对ItemsController Items属性的数据绑定检查将其更新为包含0个Items的表单,我想防止使用单向数据绑定.
What is happening now is that when I create an instance of the form and set the Items property with some values, the data-binding checks for the ItemsController Items property and updates it back to the form with 0 Items, I want to prevent that using a one-way data-binding.
是否有可能或者我将仅依靠活动?
Is it possible or I will have to rely on event's only?
推荐答案
看起来您正在寻找 Binding.ControlUpdateMode 属性:
Looks like you are seeking for Binding.ControlUpdateMode property:
获取或设置何时将对数据源的更改传播到绑定控件属性
Gets or sets when changes to the data source are propagated to the bound control property
myForm.DataBindings.Add(new Binding("Items", ItemsController.Singleton, "Items")
{
DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged,
ControlUpdateMode = ControlUpdateMode.Never
});
这篇关于单向绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!