6

Most of the Q&A I found on StackOverflow is how Binding work but x:Bind doesn't which usually solved by Bindings.Update(). However, my issue is, inside a GridView, ItemSource="{x:Bind _myList}" works but ItemSource="{Binding _myList}" doesn't.

Why? And how do I make Binding work? (instead of x:Bind)

Here's a few code thingies:

Class:

public class MyClass
{ 
    public string prop1 {get; set;}
    public string prop2 {get; set;} 
}

public class MyList : List<MyClass>
{ 
    public void Populate()
    // Add items 
}

Code Behind

public MyList _myList = new MyList();
_myList.Populate();
DataContext = this;
Bindings.Update();

XAML (doesn't work here but works if ItemSource: changed into x:Bind _myList)

<GridView ItemSource="{Binding _myList}">
 <GridView.ItemTemplate>
  <DataTemplate>
   <StackPanel>
    <TextBlock Text="{Binding prop1}"/> <TextBlock Text="{Binding prop2}/>
   </StackPanel>
  </DataTemplate>
 </GridView.ItemTemplate>
</GridView>
Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62

1 Answers1

4

The problem that your _myList is field, not property. So, change to

public MyList _myList { get; set; } = new MyList();
Andrii Krupka
  • 4,276
  • 3
  • 20
  • 41
  • Thank you very much. This worked. And I never expected asking on StackOverflow is so easy. I'm a very beginner into programming and don't understand the difference between field and property and why x:Bind works on a field and Binding doesn't, but I'm on my way looking up to learn more. – Canon Cygnus Aug 10 '16 at 05:03