I have a simple program which displays a collection on a data grid. When I run the code I do not see grid displaying data. The model is
public class Person
{
public string Name;
public int Age;
public bool Sex;
}
The view model is
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));
}
}
The view xaml
<Grid x:Name="LayoutRoot" Background="White">
<sdk:DataGrid Name="dataGrid1">
</sdk:DataGrid>
</Grid>
the code behind is
public PeopleView()
{
InitializeComponent();
PeopleViewModel model = new PeopleViewModel();
dataGrid1.ItemsSource = model.PersonList;
}