Automatically refresh a bound WPF control when values of bound object are updated
But when the values of the properties in the binding object are updated, the form itself is not being updated automatically as it still shows the previous values when displayed. How can I bind to a COBOL object and have the updated properties automatically reflected when the form is displayed?
An example program is attached to this article.
Here is the description of this example program:
This example program demonstrates how to do simple binding between an object and a textbox Text property in WPF.
It also shows how to implement the INotifyPropertyChange interface in a Visual COBOL class so that the object's properties can be bound to the form controls and have the controls be automatically updated when the value of the properties change.
If the INotifyPropertyChanges was not implemented then the Form will not be automatically updated when the property values change. Some collection classes like ObservableCollection implement this interface by default so the update is done automatically when binding to a ListView, Listbox or some other list control.
The binding Path is specified in the Window1.xaml on the Text property of each TextBox like:
and then an instance of the contactdetails class is bound to the form using:
set self::DataContext to myDetails
This class contains the properties that will be bound to the WPF Form.
In order to get the form to automatically update when any of these properties are changed we implemented the INotifyPropertyChanged interface.
To do this we must define the PropertyChanged event and the method named OnPropertyChanged and then call this method whenever one of the properties is changed through its setter method.
The PropertyChanged event will be called whenever the properties are updated.