The constructor runs before the data binding, so you are probably seeing that error because the DataContext
is null
at the time the constructor runes.
To bind to a collection, use a control that contains an ItemsSource
property. And if you want to bind to a nested collection, modify the ItemTemplate
of the control to use another control with an ItemsSource
property for the nested collection.
Here's an example using an ItemsControl
<ItemsControl ItemsSource="{Binding Processes}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding BurstTimes}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
I have some examples of the ItemsControl
on my blog if you're interested.
If you want to specify a UserControl
for each object, then set the ItemTemplate
for the first ItemsControl
to be the ProcessUserControl
, and inside the ProcessUserControl
have an ItemsControl
bound to BurstTimes
and use a BurstTimeUserControl
for it's ItemTemplate
<ItemsControl ItemsSource="{Binding Processes}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:ProcessUserControl />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
...
<UserControl x:Class="MyNamespace.ProcessUserControl ...>
...
<ItemsControl ItemsSource="{Binding BurstTimes}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:BurstTimeUserControl />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
...
</UserControl>