hi . if you want to use databinding in wpf , your model class implement INotifyPropertyChanged. see following:
public class ContactsViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(PropertyChangedEventArgs e)
{
if (PropertyChanged != null)
{
PropertyChanged(this, e);
}
}
private string _firstName;
public string FirstName
{
get { return _firstName; }
set
{
if (_firstName != value)
{
_firstName = value;
OnPropertyChanged(new PropertyChangedEventArgs("FirstName"));
}
}
}
}
and your XAML:
<DataGrid x:Name="ContactsDataGrid" ItemsSource="{Binding}">
<DataGrid.Columns>
<DataGridTextColumn FontSize="14" Header="FirstName" Width="150" Binding="{Binding FirstName}"/>
</DataGrid.Columns>
</DataGrid>
and finally in your window.xaml.cs:
ContactsDataGrid.DataContext=GetContacts();