I trying to bind a List to a DataGrid. Here is the code snippet:
public class Parson
{
public string LastName { get; set; }
public string FirstName { get; set; }
public Parson(string lastName, string firstName)
{
LastName = lastName;
FirstName = firstName;
}
}
public class Persons : List<Parson>
{
// Parameterless constructor
public Persons()
{
}
public new void Add(Person parson)
{
base.Add(parson);
}
}
the code behind:
Persons persons = new Persons();
persons.Add(new Parson("New","Person");
dataGrid1.DataContext = persons;
xaml:
<my:DataGrid Name="dataGrid1"
xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit"
CanUserAddRows="True"
ItemsSource="{Binding}"
AutoGenerateColumns="False">
<my:DataGrid.Columns>
<my:DataGridTextColumn Header="First Name" Binding="{Binding Path=FirstName}"/>
<my:DataGridTextColumn Header="Last Name" Binding="{Binding Path=LastName}"/>
</my:DataGrid.Columns>
</my:DataGrid>
the result is that an empty grid is display! anyone know why?