I have the following class
public class Car { public Name {get; set;} }
and I want to bind this programmatically to a text box.
How do I do that?
Shooting in the dark:
... Car car = new Car(); TextEdit editBox = new TextEdit(); editBox.DataBinding.Add("Name", car, "Car - Name"); ...
I get the following error
"Cannot bind to the propery 'Name' on the target control.
What am I doing wrong and how should I be doing this? I am finding the databinding concept a bit difficult to grasp coming from web-development.
Data binding is the process that establishes a connection between the app UI and the data it displays. If the binding has the correct settings and the data provides the proper notifications, when the data changes its value, the elements that are bound to the data reflect changes automatically.
Open a design surface in the editor and choose View > Data Sources. Add a data source to your project. Set the control that is created when you drag an item from the Data Sources window to the designer. Modify the list of controls that are associated with items in the Data Sources window.
As mentioned earlier, one-way data binding in Angular can be of three types i.e Interpolation, Property binding, and Event binding.
You want
editBox.DataBindings.Add("Text", car, "Name");
The first parameter is the name of the property on the control that you want to be databound, the second is the data source, the third parameter is the property on the data source that you want to bind to.
Without looking at the syntax, I'm pretty sure it's:
editBox.DataBinding.Add("Text", car, "Name");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With