0

I have some collection that implements INotifyCollectionChanged.

public sealed class GroupCollection : INotifyCollectionChanged, IList<Group>
{
    //...
    public event NotifyCollectionChangedEventHandler CollectionChanged;

    private void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
    {
        if (CollectionChanged != null)
        {
            CollectionChanged(this, e);
        }
    }
    //...
}

It is used in xaml

        <CollectionViewSource x:Name="groupedItemsViewSource" Source="{Binding Groups}"/>

then in xaml.cs

        this.DefaultViewModel["Groups"] = groups.GroupCollection;

Collection items are displayed just fine. But UI does not subscribe to CollectionChanged and doesn't updates itself when CollectionChanged is fired. Maybe I need to implement more interfaces to make UI control subscribe to event?

P.S. I cannot use ObservableCollection because compiler says that this "is not a Windows Runtime interface".

b1n0m
  • 283
  • 3
  • 10

1 Answers1

0

The following use of ObservableCollection works fine for me when using the default Grid application template:

using System.Collections.ObjectModel;
...
class MyOC : ObservableCollection<SampleDataGroup> { };
...
var oc = new MyOC();
string id = "title1";
oc.Add(new SampleDataGroup(id, id, id, "", id));
id = "title2";
oc.Add(new SampleDataGroup(id, id, id, "", id));
this.DefaultViewModel["Groups"] = oc;

I would guess that you could do something similar in your project:

using System.Collections.ObjectModel;
...
public sealed class GroupCollection : ObservableCollection<Group>
{
...
chue x
  • 18,573
  • 7
  • 56
  • 70
  • I cannot do this. `GroupCollection` is located inside another project (project type is "Windows Runtime Component"). Public class inside "Windows Runtime Component" cannot implement `ObservableCollection`. If I try, I get compilation error "`ObservableCollection` is not a Windows Runtime interface". – b1n0m Mar 06 '13 at 16:54