I posted in MSDN Forum a while ago that I ran into a WPF bug that occurs when you put one template inside another template like
<ListBox HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
Background="Honeydew" ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<ListBox ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<etc..............
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
The above code won't fail during the compilation. However,during the run, you will notice that only the first item of the outer listbox will show up but not the rest. Sam Bent, WPF/WinFX Dev Lead answered that this is a nested template bug. If template is used nestedly, the result will be unexpected. To workaround, the template should be defined as a separated template in Resources section like:
<Window.Resources>
<DataTemplate x:Key="InnerTemplate">
<StackPanel>
<ComboBox ItemsSource="{Binding Source={StaticResource CategoryData}, XPath=Category}"
SelectedValue="{Binding XPath=Category}"/>
<TextBlock Text="{Binding XPath=Title}" />
<TextBlock Text="{Binding XPath=Summary}" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="OuterTemplate">
<StackPanel>
<ListBox HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
ItemTemplate="{StaticResource InnerTemplate}" Background="Honeydew" ItemsSource="{Binding XPath=.}">
</ListBox>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<ListBox HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
ItemTemplate="{StaticResource OuterTemplate}" Background="Honeydew">
<ListBox.ItemsSource>
<Binding Source="{StaticResource InventoryData}"
XPath="*[@Stock='out'] | *[@Number>=8 or @Number=3]"/>
</ListBox.ItemsSource>
</ListBox>
</Grid>