I am trying to use the MVVM model to create a test application. I have Customers and Orders. Now, I want to display Customers list and when the user click on the customer it should display the Order.
It works perfectly when I use the following code:
<StackPanel DataContext="{Binding Path=Customers}">
<ListBox IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<UserControls:CustomerUserControl />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ItemsControl ItemsSource="{Binding Path=Orders}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
The problems comes when I replace the Orders Datatemplate to a user control.
<ItemsControl ItemsSource="{Binding Path=Orders}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<UserControls:OrderUserControl></UserControls:OrderUserControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Now, it only displays the first item in the customer.Orders collection. The OrderUserControl looks like the following:
<StackPanel>
<TextBlock Text="{Binding Path=Name}" />
<TextBlock Text="{Binding Path=Quantity}" />
</StackPanel>