I have a WPF DataGrid
bound to ObservableCollection
.
Each item in my collection has Property which is a List
.
In m
What you did by specifying <DataTemplate .../>
inside of ItemsControl
is you added this instance of DataTemplate
to default property of ItemsControl
which is Items
. So the exception you got is the expected result: first you specify the ItemsSource
, then you modify Items
. Instead you should modify ItemTemplate
property on your ItemsControl
like so:
<ItemsControl ItemsSource="{Binding Path=Exchanges}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Label>test</Label>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>