简体   繁体   中英

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);

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?

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
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM