Created On:  29 May 2012

Problem:

In Visual COBOL for Visual Studio I have a WPF Form on which I am specifying binding between several TextBox controls and properties specified in a COBOL class.  When the form is initially loaded the binding works correctly and the value of the specified binding properties are correctly displayed in the appropriate TextBox controls.

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?

Resolution:

In order for a bound control to automatically pick up changes to the values of it's bound properties you must implement the INotifyPropertyChanges interface within your object.

An example program is attached to this article.

Here is the description of this example program:

WPFBINDTEXT

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:
     Text="{Binding Path=Contact}" 
and then an instance of the contactdetails class is bound to the form using: 
     set self::DataContext to myDetails

ContactDetails Class

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.