I have a view with a viewmodel as it's DataContext. In the viewmodel I have an ObservableCollection of objects:
AvailableCategories = new ObservableCollection<Category>();
I can bind an ListView to this ObservableCollection without any trouble like this:
ItemsSource="{Binding Path=AvailableCategories}"
I now have the requirement to wrap the ObservableCollection in a class (to aid in xml serialization as in here: How to rename XML attribute that generated after serializing List of objects)
The wrapper class looks like this:
public class CategoryList : ObservableObject
{
private ObservableCollection<Category> _categories;
public ObservableCollection<Category> Categories
{
get
{
return _categories;
}
set
{
if (_categories == value)
{
return;
}
_categories = value;
RaisePropertyChanged(()=>Categories);
}
}
}
and it gets created in the VM like this:
CategoryList cl = new CategoryList();
cl.Categories = new ObservableCollection<Category>();
How do I now bind to a Collection within a wrapper class in my VM? This doesn't seem to work:
ItemsSource="{Binding cl.Categories}"
; EDIT: My VM now exposes the CategoryList like this:
private CategoryList _cl;
public CategoryList cl
{
get
{
return _cl;
}
set
{
if (value==_cl)
{
return;
}
_cl = value;
RaisePropertyChanged(()=>cl);
}
}
But still no joy.