Data binding 简单silverlight示例不在datagrid上显示我的数据

Data binding 简单silverlight示例不在datagrid上显示我的数据,data-binding,datagridview,silverlight-4.0,Data Binding,Datagridview,Silverlight 4.0,我有一个在数据网格上显示集合的简单程序。当我运行代码时,我看不到网格显示数据。模型是 public class Person { public string Name; public int Age; public bool Sex; } public class PeopleViewModel:INotifyPropertyChanged { List<Person> _personList; public PeopleViewModel

我有一个在数据网格上显示集合的简单程序。当我运行代码时,我看不到网格显示数据。模型是

public class Person
{
    public string Name;
    public int Age;
    public bool Sex;
}
public class PeopleViewModel:INotifyPropertyChanged
{
    List<Person> _personList;

    public PeopleViewModel()
    {
        _personList = new List<Person>();
        _personList.Add(new Person() { Name = "n1", Age = 20, Sex = true });
        _personList.Add(new Person() { Name = "n2", Age = 20, Sex = true });
        _personList.Add(new Person() { Name = "n3", Age = 20, Sex = true });
        _personList.Add(new Person() { Name = "n4", Age = 20, Sex = true });
        _personList.Add(new Person() { Name = "n5", Age = 20, Sex = false });
    }

    public List<Person> PersonList
    {
        get { return _personList; }
        set { _personList = value; }
    }


    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    private void RaisePropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
    }
}
视图模型是

public class Person
{
    public string Name;
    public int Age;
    public bool Sex;
}
public class PeopleViewModel:INotifyPropertyChanged
{
    List<Person> _personList;

    public PeopleViewModel()
    {
        _personList = new List<Person>();
        _personList.Add(new Person() { Name = "n1", Age = 20, Sex = true });
        _personList.Add(new Person() { Name = "n2", Age = 20, Sex = true });
        _personList.Add(new Person() { Name = "n3", Age = 20, Sex = true });
        _personList.Add(new Person() { Name = "n4", Age = 20, Sex = true });
        _personList.Add(new Person() { Name = "n5", Age = 20, Sex = false });
    }

    public List<Person> PersonList
    {
        get { return _personList; }
        set { _personList = value; }
    }


    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    private void RaisePropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
    }
}

您的DataGrid XAML是否应该包含AutoGenerateColumns=“True”?
我正在将您的代码与此类似的代码进行比较。

我绑定的集合不是公开的。这就是我的问题。

你应该考虑改变两件事。。。让您的列表成为一个可观察的集合,让您的个人列表成员使用PropertyChange@MuadDib——你应该把你的评论作为一个答案……因为这是唯一正确的答案。