Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Xamarin forms listView fill without binding

aybkekaraarslanaybkekaraarslan USMember ✭✭
edited August 2016 in Xamarin.Forms

I have a listView;

ListView listView = new ListView();
Content = new StackLayout
Children = {


    listView.ItemTemplate = new DataTemplate(() => new CustomCells());
    List<MyModel> myModels = new List<MyModel>();
    myModels.Add(new MyModel("Chris", 29, "Teen");
    myModels.Add(new MyModel("Anna", 56, "Elder");

    listView.ItemsSource = myModels;`

public class MyModel{ public MyModel(string name, int age, string type) { = name; this.age = age; this.type = type; } public string name {get; set;} public int age {get; set;} public string type {get; set;} } }

public class CustomCell : ViewCell { Label name = new Label{ Text = "{Binding name}" } int age = "{Binding age}"; (???????????????????) }

How can I get age from MyModel class? I couldn't find any solution about this. I wanna reach MyModel values like a field;
Label name = new Label { Text = }

How will it be possible?


  • MichaelRumplerMichaelRumpler ATMember ✭✭✭✭✭

    "{Binding name}" only works in Xaml. In code this is much more complicated. This should do the trick:

    Label name = new Label();
    name.SetBinding(Label.TextProperty, nameof(;

    To get the age without binding you have to do this in CustomCell:

        protected override void OnBindingContextChanged()
            var vm = (MyModel)BindingContext;
            int age = vm.age;
  • aybkekaraarslanaybkekaraarslan USMember ✭✭

    name.SetBinding(Label.TextProperty, nameof(; only get field name.
    When I run the project label text will be "name". I dont't want to this. I wanna get name value for all listview items.

Sign In or Register to comment.