Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>With only your code mentioned above, it will be thrown as the null reference exception to write a collection property in XAML due to the fact from the <a href="http://msdn.microsoft.com/en-us/library/ms753379.aspx#Collection_Properties" rel="nofollow">MSDN</a>:</p> <pre><code>The presence of that collection type is implicit whenever you specify a property in XAML that takes a collection type. </code></pre> <p>So, I suggest initializing the collection in XAML as the following, if you do not want to have the collection instance in the class declaration.</p> <pre><code>&lt;Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:system="clr-namespace:System.Collections;assembly=mscorlib" xmlns:local="clr-namespace:WpfApplication1" Title="MainWindow" Height="350" Width="525"&gt; &lt;Window.Resources&gt; &lt;local:MiniObject x:Key="RootItem" Caption="Item0" Checked="True"&gt; &lt;local:MiniObject.Content&gt; &lt;system:ArrayList&gt; -------------------------------------1) &lt;local:MiniObject Caption="Item1" Checked="True"&gt; &lt;/local:MiniObject&gt; &lt;local:MiniObject Caption="Item2" Checked="True"&gt; &lt;/local:MiniObject&gt; &lt;/system:ArrayList&gt; &lt;/local:MiniObject.Content&gt; &lt;/local:MiniObject&gt; &lt;/Window.Resources&gt; &lt;Grid&gt; &lt;ListBox ItemsSource="{Binding Source={StaticResource ResourceKey=RootItem}, Path=Content}" DisplayMemberPath="Caption"/&gt; &lt;/Grid&gt; &lt;/Window&gt; public class MiniObject { public bool Checked { get; set; } public String Caption { get; set; } public IList Content { get; set; } -----------------------------------------2) } </code></pre> <p>At the 2), you may know there are the four alternatives(IList,IDictionary, etc.) to be the collection property in XAML. Please, refer to the <a href="http://msdn.microsoft.com/en-us/library/ms753379.aspx#Collection_Properties" rel="nofollow">MSDN</a>. Above, ICollection is also OK, as the items are added to the ArrayList.</p> <p>At the 1), We cannot declare a generic type collection yet, but I know it would be supported as soon.</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