This is the code behind, an array of People (ObservableCollection ) objects.
private ObservableCollection<People> data = new ObservableCollection<People>();
public SecondWindow()
{
InitializeComponent();
data.Add(new People() { Name = "JOhn Doe", Age="34" });
data.Add(new People() { Name = "Jane Doe", Age = "45" });
data.Add(new People() { Name = "Peter Singh", Age = "26" });
this.DataContext = this;
}
public class People : INotifyPropertyChanged
{
private String name, age;
public String Name
{
get { return this.name; }
set
{
if (this.name != value)
{
this.name = value;
this.NotifyPropertyChanged("Name");
}
}
}
public String Age
{
get { return this.age; }
set
{
if (this.age != value)
{
this.age = value;
this.NotifyPropertyChanged("Age");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(String prop)
{
if (this.PropertyChanged != null) this.PropertyChanged(this, new PropertyChangedEventArgs(prop));
}
}
This is the XAML code, but it's not binding
<BlockUIContainer>
<ListView BorderThickness="0"
ItemsSource="{Binding Path=data}">
<ListView.View>
<GridView>
<GridViewColumn
Header="Name"
DisplayMemberBinding="{Binding Name}"
Width="150" />
<GridViewColumn
Header="Age"
DisplayMemberBinding="{Binding Age}"
Width="75" />
</GridView>
</ListView.View>
</ListView>
</BlockUIContainer>
Any ideas?