I have tried this:
<DataTemplate x:Key="RowItemTemplate">
<ItemsControl ItemTemplate="{StaticResource ResourceKey=BorderItemTemplate}" ItemsSource="ContentPresenter.Content">
</ItemsControl>
</DataTemplate>
and it results in a stack overflow. How to I set the ItemsSource of an ItemsControl to the content of the ContentPresenter?
Edit:
Changed ItemsSource="ContentPresenter.Content" to just ItemsSource="{Binding}" but I'm still getting a stack overflow. The ItemsSource of the main ItemsControl is set to new List<List<string>> { new List<string> { "1", "2", "3", "4" }, new List<string> { "1", "2", "3" }, new List<string> { "1", "2" }, new List<string> { "1" } }; Here is a larger piece of my code:
<UserControl.Resources>
<DataTemplate x:Key="BorderItemTemplate">
<Border RenderTransformOrigin="0.5,0.5">
<Border.RenderTransform>
<RotateTransform Angle="-135"/>
</Border.RenderTransform>
<ContentPresenter/>
</Border>
</DataTemplate>
<DataTemplate x:Key="RowItemTemplate">
<ItemsControl ItemTemplate="{StaticResource ResourceKey=BorderItemTemplate}" ItemsSource="{Binding}">
</ItemsControl>
</DataTemplate>
</UserControl.Resources>
<ItemsControl Name="comparisonGrid" ItemTemplate="{StaticResource ResourceKey=RowItemTemplate}">
</ItemsControl>
If you are just trying to set the
ItemsSourceproperty to the data you are currently templating, you can use the following:The binding is interpreted as "the value of
this.DataContext", andDataContextis always set to the value that you are templating within aDataTemplate.Edit
Looking at the OPs full code, I think that the problem is down to using the
ContentPresenterwithin theBorderItemTemplate. Assuming that the aim is to display the number to which it is bound, it should be replaced by the following: