How Do I Bind Data to a .NET Control? (Magic xpa 3.x)
You can easily bind data to the control using the control’s Data property, exactly as using Magic xpa built-in controls.
Since .NET controls have many properties and many events, before attaching a variable to the Data property, you will need to define which .NET property will get the variable value and which .NET event is the trigger to setting the variable with the .NET property value.
This definition is done in the model level in the Value Property Name and Value Changed Event Name properties.
You will now add the .NET binding declarations to your .NET control model.
This definition can be done once per each control type for which you want to bind data.
-
Create a model with GUI Display or Rich Client Display Class and set its Attribute to .NET.
-
Open the property sheet of the model and define an Object Type, such as System.Windows.Forms.MonthCalendar.
Note that you can use the auto-complete feature by pressing Ctrl+Space and whenever you insert a dot, a selection list with the available options will be opened (just like when you select a Magic xpa internal function).
-
Set the Value Property Name property to the property that will be bound to the data variable, such as SelectionStart.
-
Set the Value Changed Event Name property to the event that will be the trigger for updating back the data variable, such as DateChanged.
That’s it, now the model can be used in your programs.
You will now use the .NET control model in your program.
-
Create a new program.
-
Create a variable in this program. This variable will be used to get/set the control’s data.
-
Zoom into the form and put a .NET control on the form.
-
Assign the new model to the .NET control.
Note that only models whose object type inherits from System.Windows.Forms.Control can be used for .NET controls on a form.
-
Assign the variable you created to the Data property.
Now, any change in the data variable is seen on the control and any change in the control is updated to the data variable.
Since version: 2.1
The Online and Rich Client Samples projects (program NE11 and RNE11)