<ContentControl Content="Test">
<ContentControl.ContentTemplate>
<DataTemplate>
<Border>
<ContentPresenter />
</Border>
</DataTemplate>
</ContentControl.ContentTemplate>
</ContentControl>
It throws stackoverflow exception. However if i use any other control else than ContentPresenter it works fine even ItemPresenter also works.I knows it doesnt make any sense to have ContentPresenter there but just for Knowledge want to know. Why it throws StackOverFlow exception and also Why does Intellisense shows it can be added(I mean it comes there in Intellisense that means syntatically its not wrong to have ContentPresenter there). Any help will be highly appericiated. Or is it any flaw in Wpf.
The MSDN page for ContentPresenter says:
I imagine it gives a StackOverflow because it just keeps on trying to apply the template to the ContentPresenter in the ContentTemplate, and then on the next one inside it, and then the one inside it, etc.
You also can do things like the following, so this pattern probably isn’t always wrong, even though IntelliSense probably doesn’t do any checking for these sorts of scenarios.