views:

41

answers:

1

There is an interface:

public interface IFoo {
}

A Silverlight user control has a collection of IFoo instances:

public ObservableCollection<IFoo> Items { get; set; }

There is an abstract class that implements the interface:

abstract public class Foo : IFoo {}

And a class that further derives from that:

public class DerivedFoo : Foo {}


With all of that said, I'm trying to add instances of DerivedFoo into the control's collection via XAML, but I receive an error that DerivedFoo is not of type IFoo and cannot be used in the generic collection.

I did find a post in a forum that said this was a bug in Silverlight 3 but would be fixed (I am using Silverlight 4). Is this still a bug or am I going about this incorrectly?

Update: My code is at home and I'm at work so I can't post the actual XAML, but from memory it was along the lines of:

<my:Thing>
    <my:Thing.Items>
        <my:DerivedFoo ... />
    </my:Thing.Items>
</my:Thing>
A: 

The answer is...

The CollectionChanged event handler for the generic collection made an improper cast during the Add action.

oakskc