Take the 2-minute tour ×

i'm using an ItemsControl to generate a list of controls based on my model. When looking at the visual tree, i noticed that each of the rendered control is wrapped in a ContentPresenter. The controls that are added are a 3rd party control and are designed to display a splitter between each control if they are siblings..this allows a user to size each control. For example the following will show a splitter between each of the controls at run time.

<3rdPartyControl />
<3rdPartyControl />
<3rdPartyControl />

When using an ItemsControl, each of the 3rdPartyControl are wrapped in a ContentPresenter, and thus no splitter is shown. I have tried various ways to try and solve this problem but unable to get this to work unless i write code behind to add each control rather than rely on Xaml. Does anyone know of a way to replace the contentpresenter completely (in my case with 3rdpartyControl)?


share|improve this question
why do you think ContentPresenter is the reason that splitter doesn't work? –  ArsenMkrt Dec 14 '12 at 22:50
because if i add 3 of the controls as in my example without using an ItemsControl, it works as expected. Using snoop to look at the difference, i see that in the case it doesn't work, the contentpresenter wraps the controls...that's the only difference. –  mike01010 Dec 14 '12 at 22:53
Is this when you even specify your own ItemsPanelTemplate (StackPanel) for the ItemsControl? –  Chris W. Dec 14 '12 at 22:57
ItemsPanel template will wrap the entire list of items i believe. What i need is to generate a visual tree w/o that ContentPresenter around each control that is generated. Out of desparatio and curiousity..i tried specifying a custom ItemsControl.ItemsPanel, ItemsControl.Template and ItemsControl.ItemContainerStyle to get these controls to render as sequential siblings. In none of these cases did the expected behavior work and when checking the visual tree, i continue to see each of the controls wrapped by ContentPresenter. –  mike01010 Dec 14 '12 at 23:05

2 Answers 2

up vote 4 down vote accepted

In order to replace the ContentPresenter you could derive from ItemsControl and override the GetContainerForItemOverride method to create a specialized container control.

ListBox for example overrides this method to create a ListBoxItem as container for a new item object.

share|improve this answer
This seems to do the trick, but for some reason it is not calling my DataTemplate to render content. i do see the custom controls in the visual tree however..they just have no content. not sure why... –  mike01010 Dec 14 '12 at 23:33
In order to make a DataTemplate work, you'd need a control that can deal with a DataTemplate (ContentPresenter for example :-). You can however provide a Style for your container by setting the ItemContainerStyle property. –  Clemens Dec 14 '12 at 23:37
hmmm..this is getting messy. the new container is a DevExpress LayoutGroup control to which i want to add a chart control as a child...the LayoutGroup doesn't even have a template property. –  mike01010 Dec 15 '12 at 0:12
Sorry, i don't know that one. –  Clemens Dec 15 '12 at 0:14
that's ok, i think your answer will be helpful to others encountering the same issue. thanks –  mike01010 Dec 15 '12 at 0:16

That's true, every element that you add to ItemsControl is wrapped with ContentPresenter, you can find more details about it in the greate series of articles from dr.wpf ItemsControl a-z

One way I would suggest to try is to change ItemsControl to ListBox and make ListBox act like ItemsControl. In this case you can re-style/re-template ListBoxItem and replace ContentPresenter with your control. You would also need to stop selection support. Here is ListBox style that you need to change.

share|improve this answer
I did try using a listbox by re-templating...but if recall, the issue here is similar, each control rendered is wrapped in a ListBoxItem. –  mike01010 Dec 14 '12 at 23:11

Your Answer


