I have an object like so:
class RCLocation : INotifyPropertyChanged
{
private string _id;
private string _name;
private bool _checked;
public string Id { /* get/set with NotifyPropertyChanged() */ }
public string Name { /* get/set with NotifyPropertyChanged() */ }
public bool Checked { /* get/set with NotifyPropertyChanged() */ }
/* INotifyPropertyChanged implementation methods */
}
Now in my MainWindow.xaml I have an ItemsControl like so:
<ItemsControl Name="lstDropOff" ScrollViewer.VerticalScrollBarVisibility="Auto">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding Checked, Mode=TwoWay}"/>
<TextBlock Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
I bind the data to this list in my code behind like so:
ObservableCollection<RCLocation> dropOffs = new ObservableCollection<RCLocation>();
lstDropOff.ItemsSource = dropOffs;
dropOffs.Add(new RCLocation { /* some data here */ });
dropOffs.Add(new RCLocation { /* some data here */ });
dropOffs.Add(new RCLocation { /* some data here */ });
dropOffs.Add(new RCLocation { /* some data here */ });
The items I have just added do not show in the ItemsControl. What exactly am I doing wrong? Can't figure it out :/
Thanks for help.