Default Item Template and ICollectionView

Topics: Bugs, Conventions
May 1, 2012 at 8:57 AM

Hi All,

I had an application which was binding a listbox to an ObservableCollection of view models.  This worked nicely, using the default template to automatically bind the view on each of the items in it.

I decided to add some filtering and sorting to this list and so changed the listbox to bind to an ICollectionView, which had the ObservableCollection as it's source.  The binding works fine, but having looked at the code, it seems it's not applying the default item template, because the convention manager checks to see whether the collection you are binding to is a generic type, which in the case of the ObservableCollection it is, and the ICollectionView it is not, so it does not apply the template.

I know one work around would just be to use the XAML from the default template as the item template for the listbox, but I was wondering if firstly this is by design or possibly something that could be addressed, and also if there is a more elegant solution I could implement on my part ?

Many thanks in advance,


Mar 19, 2013 at 9:27 PM
Edited Mar 19, 2013 at 9:30 PM
I have the same problem -- any suggestions?

edit: Just saw this thread:
Mar 20, 2013 at 12:43 AM
@blah238 - you tried my fix to this issue, but the same problem happens with the filter applied when you use my fix?
Mar 20, 2013 at 9:32 PM
Edited Mar 20, 2013 at 9:33 PM
No I think your fix works great. As I mentioned in the other thread, I think it's just my design causing me confusion.

Basically what I'm doing is filtering two collections based on their items' membership in a third collection. They don't get automatically notified when items are added to or removed from the third collection so I have to manually reset the filter when that happens.

If you have any suggestions on better ways to handle that I'd be interested in hearing it but that's an unrelated issue I think.