Search code examples
bindingtextboxwindows-phone-7

Binding textbox with list of items


I am trying to create my first app for Windows Phone 7.

I have a Detail View and the .cs class associated with the view.

In my view, I have :

  <StackPanel Grid.Row="0" Grid.Column="0">
  <TextBlock Name="textBlock1" Text="..."/>
  </StackPanel>

In the .cs:

  ...
  listAgences = new List<Agence>();

  Agence agence1 = new Agence();
  agence1.Name = "test";
  agence1.Adresse = "test1";
  ...
  listAgences.Add(agence1);
  ...

How do I get to have the Text in the textbox to be "test"?

I tried stuff like:

  Text="{Binding Path=listAgences[0].Name}";

I know how to do this in ASP.NET, but here I'm quite lost.


Solution

  • Presuming that your datacontext class has a public property List<Agence> ListAgences { get; set; } then binding like that should work, though.