0

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>
3
  • Can you post your XAML where you add instances to the collection? Commented Jul 14, 2010 at 12:33
  • This should work in Silverlight 4 and its new XAML parser. Can you verify the version? Commented Jul 14, 2010 at 17:58
  • Yes, the Silverlight target version for the project is listed as "Silverlight 4". Commented Jul 14, 2010 at 21:09

1 Answer 1

1

The answer is...

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.