Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You're trying to use XAML's implicit collection syntax. In order to do this, the property (<code>Content</code>, in this case) must be of a type that implements <code>ICollection</code>. Note: not <code>ICollection</code>, but a type that implements <code>ICollection</code>.</p> <p>You can't just use an interface because the <code>XamlReader</code> needs to know what type of object to create. If you haven't told it the type, how should it decide? By searching through all of the types available to your assembly, finding the ones that implement <code>ICollection&lt;MiniObject&gt;</code>, discarding the ones that don't have a parameterless constructor, and then choosing one at random? No. </p> <p>When you define <code>Content</code> as <code>List&lt;MiniObject&gt;</code>, the <code>XamlReader</code> knows what type of object it should create. Since that's a type that implements <code>ICollection</code>, it can use the implicit collection syntax. So it just creates the object and calls <code>Add</code> to add the child items, and if you stuck a child item in there that isn't a <code>MiniObject</code> you'll get a runtime error.</p> <p>You say that "I need to avoid using an actual implementation" in your <code>Content</code> property. In that case, you cannot use the implicit collection syntax. You will need to do what you do in your second example: explicitly define a type that implements <code>ICollection&lt;MiniObject&gt;</code>, and add a child element in your XAML to create it explicitly.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload