Reputation: 1
I have an object model class ( desarlise json to object model ) , i want to use binding to attach the object model to the UI using xamarin forms.
P.S not natively nor XAML but through code.
Have search the internet but its getting more and more confusing
Any help will be anxiously helpful
Thanks
Upvotes: 0
Views: 1436
Reputation: 16232
Your question is a bit unclear, but here's an example of data binding for Xamarin.Forms
in code.
//INPC implementation removed in this sample
public class PersonViewModel
{
public string FirstName {get;set;}
public string LastName {get;set;}
}
var person = new PersonViewModel {
FirstName = "John",
LastName = "Doe",
};
var first = new Label ();
first.SetBinding (Label.TextProperty, "FirstName");
var label = new Label ();
label.SetBinding (Label.TextProperty, "LastName");
var personView = new StackLayout {
Orientation = StackOrientation.Horizontal,
Children = {
first,
last
}
};
personView.BindingContext = person;
Upvotes: 1