When implementing a tree view in WPF, I commonly put a dummy, null, entry in the ObservableCollection<T> of children. This causes the tree view to display the [+] expander, and then I handle the expansion event (by binding IsExpanded) by "realizing"
the actual content -- i.e. removing the null entry and going to the database/service/whatever.
This means that I've got, in my viewmodel object's constructor.
_children = _model.Children.Where(predicate).Select(m => new TreeNodeViewModel(this, m, predicate));
Obviously, the call to Add throws AccessViolationException, because _children is actually a ReadOnlyContinuousCollection. Is there any way around this? For example, would it be feasible for me to write an extension such that:
_children = _model.Children.Where(predicate).Select(m=>etc).Lazy();
Any other suggestions/ideas?