0
votes

I am trying to bind listbox from xaml, but seems I am doing something wrong with it. Here is my XAML Page.

<Grid x:Name="LayoutRoot" Background="Transparent">
<!--Pivot Control-->
<phone:Pivot Title="MY APPLICATION">
<!--Pivot item two-->
<phone:PivotItem Header="item2">
<Grid>
  <ListBox Foreground="Black" x:Name="ls" ItemsSource="{Binding MyLang}" >
    <ListBox.ItemTemplate>
      <DataTemplate>
        <TextBlock Text="{Binding Language}"></TextBlock>
      </DataTemplate>
   </ListBox.ItemTemplate>
  </ListBox>
</Grid>
</phone:PivotItem>
</phone:Pivot>
</Grid>

code behind

DataSource ds = null;
public List<TranslationLanguage> MyLang;
public PivotPage2()
{
    ds = new DataSource();
    MyLang = ds.getTranslationLanguages(); //return collections and contains 13 rows
    InitializeComponent();
    DataContext = this;
}
public class TranslationLanguage
{
        [PrimaryKey]
        public byte LanguageID{get;set;}
        public string Language{get;set;}
        public string Description { get; set; }
        public bool IsActive { get; set; }
        public FlowDirection FlowDirection { get; set; }
        public string DownloadURL { get; set; }
        public bool IsDownloaded { get; set; }
        public string ImagePath { get; set; }
}

I am really confused why it doesn't work at all?

3

3 Answers

4
votes

Binding can be done only on properties, MyLang is not a property. Make MyLang a property

public List<TranslationLanguage> MyLang{ get; set;};
0
votes

Since you have the datacontext bound from the code behind, you need to set the Datacontext of the Window as

DataContext="{Binding RelativeSource={RelativeSource Self}}
-1
votes

You have to do like this:

DataContext="{Binding RelativeSource={RelativeSource Self}}