开发者

Can't create a custom class ObservableCollection<ObservableCollection<T>>

Why I can't define the LLSGroupsWithItems in the following example (it won't compile):

public class LLSGroupsWithItems<Group<T>> : ObservableCollection<Group<T>>
    {

    }

    public class Group<T> : ObservableCollection<T>
    {
        public Group(string name, IEnumerable<T> items)
        {
            this.Key = name;
            foreach (T item in items)
            {
                this.Add(item);
            }
        }

        public override bool Equals(object obj)
        {
            Group<T> that = obj as Group<T>;

            return (that != null) && (this.Key.Equals(that.Key));
        }

        public string Key
        {
            get;
            set;
        }
    }

The compiler error is:

Type parameter declaration must be an identifier not a type.

Long story:

I have seen an example on WindowsPhoneGeek about how to dynamically add items to a structure of a form ObservableCollection<ObservableCollection<T>>, but I want to encapsulte an automatic grouping functionality within the collection that my LongListSe开发者_运维问答lector is bound to, so that I don't have to always look, what group to add a particular item to. For this, I suppose, I need to create a class I am trying to define, but C# limitations or something won't let me. Please explain why. Thanks.


Shouldn't this

public class LLSGroupsWithItems<Group<T>> : ObservableCollection<Group<T>>
{
}

be written like this instead?

public class LLSGroupsWithItems<T> : ObservableCollection<Group<T>>
{
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜