Question : Silverlight Listbox  Binding

I'm trying to get a simple list of T to bind to a listbox. The listbox is binding but the text that I'm trying to display is not displaying. You can choose between items and if you debug with some extra code you can pull the data from the class object.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:

    
        
            
                
                    
                        
                        

                    
                

            
        
    


namespace testlistbox
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
            InitializeComponent();
        }

        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {


            PersonList.DataContext = MakePersonList();
            PersonList.SelectedIndex = -1;
           
        }
        private static List MakePersonList()
        {
            return (new List()
            {
               new Person() { FirstName = "John", LastName = "Smith" },
               new Person() { FirstName = "John", LastName = "Jones" }
            });

        }
      
    }
    class Person
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        
    }
}

Answer : Silverlight Listbox  Binding

Believe me.  It works 100%.

Did you copy complete code from my XAML and XAML.CS files?

If not, do this first.  Create new Project, give exactly same file names (leave default MainPage.xaml).
Delete everything in XAML and copy and paste.  Do samething with xaml.cs file.

Make sure ListBox shows data.  Let me know what happens.

Then try to modify it.

HTH
Ashok
Random Solutions  
 
programming4us programming4us