omer raza
omer raza

Reputation: 1

Bind Object Model to UI in xamarin forms

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

Answers (1)

Stephane Delcroix
Stephane Delcroix

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

Related Questions