Skip to content

Internal MailBag: Collection Types in XAML

February 26, 2007

Another mail that mail be useful to others outside our firewall…

By the way, MSDN has a section that goes into Collection Types and XAML Collection Properties


From: Mike
Btw, the reason List<T> works is because it implements IList.

From: Rob
IList, IDictionary or Array are the collection types we support.

List<T> or IList<T> is recommended as well, as it suggests the type of the children.

IList<T> isn’t supported by itself…partially due to dev time and partially due to perf concerns…if I recall correctly.

From: Developer
I’m designing a class that I want to be able to use in XAML.  The class which has a collection-valued property called “Children”.

If I define “Children” as IList<T>, I get the following error:  ‘Children’ is a read-only IEnumerable property, so ‘MyClass’ must implement IAddChild.

If I define “Children” as List<T>, things seem to work fine.

Can someone clarify what types XAML supports for collections?  Why is IList<T> not acceptable?  What is the recommended usage here?


From → XAML (non-UI)

  1. Michael permalink

    I\’ve seen a similar but strange issue pop up when using a HierarchicalDataTemplate. If I attempt to bind the ItemsSource to a property named Children (that implements IList<T>) then I get an error. If I rename the property to Kids, it works fine.

  2. Owen permalink

    In my opinion the easiest to use for this purpose are:
    System.Collections.ObjectModel.Collection and
    System.Collections.KeyedCollection (great for named items)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: