0

Im new to data binding in Windows Phone 7 and cannot get this code to work. First, here is my "Move" Class:

public class Move
{
    public string RollNumber {get; set;}
    public string Description {get; set;}
}

Now here is my list which is made upon loading the page:

    public Game()
    {
        InitializeComponent();
        Loaded += new RoutedEventHandler(Game_Loaded);
    }

    void Game_Loaded(object sender, RoutedEventArgs e)
    {
        List<Move> Moves = new List<Move>();

        Move thisMove = new Move();
        thisMove.RollNumber = "6";
        thisMove.Description = "Danny Winrars with a 6";

        Moves.Add(thisMove);
        GameHistoryList.ItemsSource = Moves;
    }

Finally, here is my XAML:

<ListBox Name="GameHistoryList">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel>
                                    <TextBlock Text="{Binding RollNumber}"></TextBlock>
                                    <TextBlock Text="{Binding Description}"></TextBlock>
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>

Anyone have any ideas on why this doesn't work? :)

dannybrown
  • 1,083
  • 3
  • 13
  • 26

1 Answers1

3

Change

<ListBox Name="GameHistoryList">

to

<ListBox x:Name="GameHistoryList">
keyboardP
  • 68,824
  • 13
  • 156
  • 205
  • Was always curious why this was the case. Ended up here, in case anyone is curious http://stackoverflow.com/questions/589874/in-wpf-what-are-the-differences-between-the-xname-and-name-attributes – William Melani Jan 11 '12 at 06:57